|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Set FocusHi all, if you have two text boxes on a form and the first only allows 10
characters, how do you set the focus to the second box after the 10th character is entered in the 1st box? Thanks in advance. Mike wrote:
> Hi all, if you have two text boxes on a form and the first only allows 10 Use one of the Key events, probably KeyUp, to calculate the current> characters, how do you set the focus to the second box after the 10th > character is entered in the 1st box? > > Thanks in advance. length of the Text property. Once it hits 10 characters, switch the focus by setting the Focus property of the second textbox. I don't know what a key event is. Can you give an example?
<za***@construction-imaging.com> wrote in message Show quoteHide quote news:1151522328.868580.319620@p79g2000cwp.googlegroups.com... > > Mike wrote: >> Hi all, if you have two text boxes on a form and the first only allows 10 >> characters, how do you set the focus to the second box after the 10th >> character is entered in the 1st box? >> >> Thanks in advance. > > Use one of the Key events, probably KeyUp, to calculate the current > length of the Text property. Once it hits 10 characters, switch the > focus by setting the Focus property of the second textbox. > Hi Mike,
Here is the code: Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged If Me.TextBox1.Text.Length = 10 Then Me.TextBox2.Focus() End If End Sub I used the text changed event. Using key up and down will need more work since you need to know what keys were pressed. Ahmed Mike wrote: Show quoteHide quote > I don't know what a key event is. Can you give an example? > > > > > <za***@construction-imaging.com> wrote in message > news:1151522328.868580.319620@p79g2000cwp.googlegroups.com... > > > > Mike wrote: > >> Hi all, if you have two text boxes on a form and the first only allows 10 > >> characters, how do you set the focus to the second box after the 10th > >> character is entered in the 1st box? > >> > >> Thanks in advance. > > > > Use one of the Key events, probably KeyUp, to calculate the current > > length of the Text property. Once it hits 10 characters, switch the > > focus by setting the Focus property of the second textbox. > > Its a wrapper for an keyboard event occuring - looks something like this and
will trigger when your textbox has focus and a key is pressed. Private Sub TextBox1_KeyPress( ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles TextBox1.KeyPress End Sub Read about it here. http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.keypress.aspx Regards John Timney (MVP) Show quoteHide quote "Mike" <ward***@swbell.net> wrote in message news:0oBog.109871$H71.70852@newssvr13.news.prodigy.com... >I don't know what a key event is. Can you give an example? > > > > > <za***@construction-imaging.com> wrote in message > news:1151522328.868580.319620@p79g2000cwp.googlegroups.com... >> >> Mike wrote: >>> Hi all, if you have two text boxes on a form and the first only allows >>> 10 >>> characters, how do you set the focus to the second box after the 10th >>> character is entered in the 1st box? >>> >>> Thanks in advance. >> >> Use one of the Key events, probably KeyUp, to calculate the current >> length of the Text property. Once it hits 10 characters, switch the >> focus by setting the Focus property of the second textbox. >> > > Mike wrote:
> I don't know what a key event is. Can you give an example? In the IDE Code window for the Form, select the text box control in theleft hand drop down. In the right hand drop down, there will be a list of available events. Select KeyUp (or whatever) and a declaration for that event will be inserted in your code. Just add your length checking code there. Or as others have posted, there are several events that can accomplish this task, including the TextChanged event. Show quoteHide quote > > > > > <za***@construction-imaging.com> wrote in message > news:1151522328.868580.319620@p79g2000cwp.googlegroups.com... > > > > Mike wrote: > >> Hi all, if you have two text boxes on a form and the first only allows 10 > >> characters, how do you set the focus to the second box after the 10th > >> character is entered in the 1st box? > >> > >> Thanks in advance. > > > > Use one of the Key events, probably KeyUp, to calculate the current > > length of the Text property. Once it hits 10 characters, switch the > > focus by setting the Focus property of the second textbox. > > |
|||||||||||||||||||||||