|
-
Apr 18th, 2005, 02:39 PM
#1
Thread Starter
Lively Member
Newbie KeyPress question... [RESOLVED]
This is so elementary, I know. I want to simply move to the next TabStop with the press of the period key (like in an IP configuration dialog). I think I need the use the KeyPress event, but I'm not sure. Should be like, one line of code. I would also like to do the same when MaxLength is reached, but that's less important.
Thanks,
CP
Last edited by milkmood; Apr 18th, 2005 at 03:53 PM.
-
Apr 18th, 2005, 02:47 PM
#2
Re: Newbie KeyPress question...
yes keypress would be fine. when the keypress event fires, use the event arguments that are passed in (as e) to determine if a "." was pressed. That should get you started, post back if you get stuck
-
Apr 18th, 2005, 02:55 PM
#3
Thread Starter
Lively Member
Re: Newbie KeyPress question...
Like I said, total newbie. Some sample code would be very helpful. The next field is the next tabstop, of course. ConfIP01 is a textbox, as is ConfIP02, 03, and 04, followed by a port textbox.
VB Code:
Private Sub ConfIP01_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ConfIP01.KeyPress
End Sub
Thanks.
CP
-
Apr 18th, 2005, 03:19 PM
#4
Re: Newbie KeyPress question...
here you go.. you owe me a cookie
VB Code:
Private Sub CheckForPeriod(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtIP1.KeyPress, txtIP2.KeyPress, txtIP3.KeyPress, txtIP4.KeyPress
'CHECK FOR A "."
If e.KeyChar = "."c Then
'SET HANDLED TO TRUE SO THE "." IS NOT PROCESSED
e.Handled = True
'SEND THE TAB KEY TO GO TO THE NEXT CONTROL
Me.ProcessTabKey(True)
End If
End Sub
you will notice this routine does the following
1) checks for a . being entered in any of the 4 IP boxes (notice this routine HANDLES 4 different keypress events - one from each IP box)
2) sets handled to true so a . doesn't come up in the textbox
3) sends a tab keypress to the form which will send focus to the next item in the taborder
-
Apr 18th, 2005, 03:52 PM
#5
Thread Starter
Lively Member
Re: Newbie KeyPress question...
That's what I needed...someone to hold my hand. Thanks a lot. Sending cookie now.
After I decided to do it this way, I realized 2 things. (1) I'll have to add the periods in in the code, and (2) there's no way to look for a machine name using the 4 IP boxes...SO, I'm going to just use a textbox. It's a configuration that will probably only be used once. It's to connect to a database within the network. After that, it will keep the connection (not persistent, but keep the settings).
Thanks again,
CP
-
Apr 18th, 2005, 03:59 PM
#6
Frenzied Member
Re: Newbie KeyPress question... [RESOLVED]
you can still use 4 seperate boxes. just concatenate them together and add the '.' between each:
visual basic code:
dim ip as new stringbuilder
ip.append(textbox1.text)
ip.append(".")
ip.append(textbox2.text)
ip.append(".")
ip.append(textbox3.text)
ip.append(".")
ip.append(textbox4.text)
ip.tostring
-
Apr 18th, 2005, 04:04 PM
#7
Thread Starter
Lively Member
Re: Newbie KeyPress question... [RESOLVED]
I may do that and use a separate box to look for the machine by name.
Thanks,
CP
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|