Setting focus on frm..._Load
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.
I've tried that, unfortunately...
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! >:(
had the same problem with vb6
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.
Quote:
but you could set the Tab Index field to 0 so that the focus is on that field when the form is loaded.