Click to See Complete Forum and Search --> : Setting focus on frm..._Load
jhemphill
June 20th, 2002, 01:15 PM
Can someone tell me why....
txtLastName.Focus()
Does NOT WORK when loading my .NET forms?
That is the last line listed in the Load event of my form.
I have also implemented a Private m_Loaded as Boolean variable that I set in the Load event, then I make sure this variable is set to True before running any code in the TextChanged events of any of my text boxes, Click events of checkboxes, Change event of combo boxes, as well as the Form_Resize and Form_Move events as well.
Could someone tell me what ELSE runs before/after the Load event that may be screwing this up?
I'd appreciate the help.
lilshoob
June 21st, 2002, 07:02 AM
This isn't an answer to your problem, but you could set the Tab Index field to 0 so that the focus is on that field when the form is loaded.
I've tried the Focus method without loading any dataset, and it defaults to the field with the Tab Index of 0.
jhemphill
June 21st, 2002, 08:59 AM
the majority of the forms have frames around the text boxes that I'm trying to set focus to. And for some reason, .NET doesn't see the text box as the focal point, it sets the focus to the frame. Which is the same thing it does when I use the .Focus() method in the Load event incidently.
If the text box is NOT in a frame, your method works, but then, so does the .Focus()! It is a very frustrating situation.
I wonder, if I simulate the look of the frames with lines.... god, this is going to be a lot of work for something that should be simple! >:(
rajtofar
June 26th, 2002, 07:30 AM
well, We have another one. that runs after form load I guess.
Thats' Form_activate.
try it an' see....
rajtofar.
jhemphill
June 26th, 2002, 09:22 AM
Actually, in .NET the Activate event only fires if the user leaves your application, and then comes back to it. Via Alt-Tab or whatever. This has been quite the source of frustration to me as well, considering that in VB6 (from which I'm upgrading this huge app..) the Activate fired every time you entered the form, after the load and if it had already been loaded, it was the only thing that ran...
Relying on this order of events was a mistake it appears. At least for anyone trying to upgrade to .NET, because .NET just LAUGHS at it. And screws everything up! >:(
Now, that being said. I did try putting my .Focus() call into the Activate event sir, but it didn't work :(
undecided
July 3rd, 2002, 12:33 PM
I do C# right now so i don't know if the principle in vb6 still applies. Basically, you can't use the method because the form is not yet shown. In VB6, I used to put Me.Show before calling the setfocus method of a control. But spare yourself from this and follow lilshoob's advice.
but you could set the Tab Index field to 0 so that the focus is on that field when the form is loaded.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.