Results 1 to 7 of 7

Thread: Newbie KeyPress question... [RESOLVED]

  1. #1

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    Resolved 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.

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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

  3. #3

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    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:
    1. Private Sub ConfIP01_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ConfIP01.KeyPress
    2.  
    3. End Sub

    Thanks.
    CP

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Newbie KeyPress question...

    here you go.. you owe me a cookie
    VB Code:
    1. Private Sub CheckForPeriod(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtIP1.KeyPress, txtIP2.KeyPress, txtIP3.KeyPress, txtIP4.KeyPress
    2.         'CHECK FOR A "."
    3.         If e.KeyChar = "."c Then
    4.             'SET HANDLED TO TRUE SO THE "." IS NOT PROCESSED
    5.             e.Handled = True
    6.             'SEND THE TAB KEY TO GO TO THE NEXT CONTROL
    7.             Me.ProcessTabKey(True)
    8.         End If
    9.     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

  5. #5

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    Resolved 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

  6. #6
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    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




  7. #7

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    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
  •  



Click Here to Expand Forum to Full Width