Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to make a form get the focus?

Status
Not open for further replies.

Takusaan

Programmer
Sep 20, 2000
29
US
I am making my main form call another form programatically.
But I am noticing that the focus goes briefly to that form then goes right back to the main form.
How can I get the call form to have the focus instead of the main?
 
Make your second form modal.

HTH,
Weedz (Wietze Veld)
veld4663@exact.nl
The Netherlands

They cling emotionally to code and fix development rather than choosing practices based on analytical assesments of what works best.

After the GoldRush - Steve McConnell
 
I don't make forms modal if possible, could you tell us where you are calling the new form from? Throughout my multiuser applications I call forms from forms.
 
Hey Wbstrider, I call the second form by issuing this:
this.cmdOpen.click in the Activate method of the main form which has this command button 'cmdOpen'
 
Takusaan

There is something in your code/properties in one or other form to create this behaviour.

To test normal form behaviour, create a new form from the form class and call it Form1. Add a cmdButton, with DO FORM form2 in the click event. DO not change any other properties.

Create a new form from the form class and call it form2. DO not change any other properties.

Run form1 and click on the cmdButton. You will then be able to click and getfocus on either form.

Apart from the cmdButton.Click() event, there is no code in either form, and the behaviour is as one would expect.

You will need to examine all the properties and events of both your problem forms.

Make copies and if you then right click on the "All" tab on the properties sheet in each form and select "Non default", you will see all the non default properties and methods. I would then start setting them back to default/testing etc until you find the problem.

Good luck!

Chris :)
 
Takusaan

this.cmdOpen.click in the Activate method of the main form which has this command button 'cmdOpen'


Move this to the .Init() event

Chris :)
 
Activate event does the specified acts before the form is ativated and so the second forms gets shown and then the first form continues.

So, the contents of the Activate event needs to be shifted to some other event suitably. May be Init() OR some other event after it.

ramani
 
If you put a form call in the activate event, the activate event will finish by activating itself. So yes, your second form gets the focus, but when the activate event is finished focus will turn to your frst form again.

What you can do is disable the first form as long as you second form is active by setting the enabled property of your first form to .F.

As soon as the second form is destroyed, enable the first form.

This construction works very fin when you use formsets, in which you would use the formset as a sort of mediator design pattern, where the forms are not aware of each others existence, and everything is handled(mediated) by the formset.

I suggest you try the disable/enable contrustion.

HTH,

Weedz (Wietze Veld)
veld4663@exact.nl
The Netherlands

They cling emotionally to code and fix development rather than choosing practices based on analytical assesments of what works best.

After the GoldRush - Steve McConnell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top