How to set focus to one control when a form pop up?
hello guys, i want to set focus to a textbox when the form pop up so that the user can enter directly instead of first pointing to the textbox then entering..
I tried put textbox1.focus() in the form_load event, but it doesn't work. anybody know how to deal with it?
cheers
Re: How to set focus to one control when a form pop up?
Try disabling it and enabling it?
Re: How to set focus to one control when a form pop up?
Quote:
Originally Posted by sunsunlight
hello guys, i want to set focus to a textbox when the form pop up so that the user can enter directly instead of first pointing to the textbox then entering..
I tried put textbox1.focus() in the form_load event, but it doesn't work. anybody know how to deal with it?
cheers
Re: How to set focus to one control when a form pop up?
textbox1.select!
it works!
tks!
Re: How to set focus to one control when a form pop up?
If you set the tab order correctly, the first item (0 or 0.0 if using groupboxes) will be the first control to have focus.
Re: How to set focus to one control when a form pop up?
Quote:
Originally Posted by Ideas Man
If you set the tab order correctly, the first item (0 or 0.0 if using groupboxes) will be the first control to have focus.
if your control is in a GroupBox, so the Groupbox it must have a tab index smaller than the controls in it ...
;)
Re: How to set focus to one control when a form pop up?
what is the difference between
and
i have always tried text1.focus , and it didn't work for the first time with the form.
strange, any1 got explanation ??
thx
Re: How to set focus to one control when a form pop up?
Quote:
Originally Posted by Zakary
if your control is in a GroupBox, so the Groupbox it must have a tab index smaller than the controls in it ...
;)
I didn't quite understand that sorry.
Re: How to set focus to one control when a form pop up?
Quote:
I didn't quite understand that sorry.
well that means if you have a textbox in a groupbox inside your form.
you cannot set the tabindex of your textbox to 0 , why ?? because it is contained in a group box that must has a smaller tabindex than the tabindex of it's contained controls.
:thumb:
Re: How to set focus to one control when a form pop up?
With textbox, you can use SelectAll() method to select all text in that textbox.
Code:
with txt1
.focus()
.selectall()
end with
Re: How to set focus to one control when a form pop up?
Quote:
Originally Posted by maged
well that means if you have a textbox in a groupbox inside your form.
you cannot set the tabindex of your textbox to 0 , why ?? because it is contained in a group box that must has a smaller tabindex than the tabindex of it's contained controls.
No, that's not true at all. When you create groupboxes it groups all the controls together, along with their tab orders. You then must specify a "tab order" for the groupboxes, and then the controls inside it.
The tab order for the groupboxes specifies in what order the groups of controls are selected, and once a groupbox has "focus", it then works in it's internal list of controls and works on the internal tab order of the controls.
This is why when you have groupboxes, you get a tab order of x.y for controls in a groupbox and x for a groupbox. It's also the reason why it can differentiate between two controls in different groupboxes with the same tab order.
Please note: If this doesn't make sense I'm sorry, I understand how it works, just not quite how to put it into words lol.