Set focus on keypress (newb)

Discussion in 'Programming General' started by Swan, Mar 9, 2007.

Set focus on keypress (newb)
  1. Unread #1 - Mar 9, 2007 at 6:38 PM
  2. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    Set focus on keypress (newb)

    Okay guys, I'm looking for ways on how to set focus to a textbox if I press a key (namely, the backslash character). Any help would be appreciated.

    Thanks in advance.
     
  3. Unread #2 - Mar 9, 2007 at 6:53 PM
  4. Skeletron
    Referrals:
    0

    Skeletron Guest

    Set focus on keypress (newb)

    You mean, like if you type in a key in a textbox, then it will add that keypressed value into another textbox.

    Here:
    This code will look for the ASCII characters 0 to 120. It will then input the value into textbox2. Although, textbox1 is not selected then it will not appear the keypressed in textbox2.

    To make it check the backslash key, just delete the For loop and replace the I with the ASCII chr.

    ~Skeletron
     
  5. Unread #3 - Mar 9, 2007 at 8:09 PM
  6. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    Set focus on keypress (newb)

    What I mean is, if I press the backslash key while the form is in focus, then it will set the focus to the search box.
     
  7. Unread #4 - Mar 9, 2007 at 9:06 PM
  8. ray230
    Referrals:
    0

    ray230 Guest

    Set focus on keypress (newb)

    What does focus mean?


    ^^^^^^^^^^^^^^^^^

    Newb Question.
     
  9. Unread #5 - Mar 9, 2007 at 9:17 PM
  10. DisturbedOne
    Joined:
    Jan 21, 2007
    Posts:
    54
    Referrals:
    0
    Sythe Gold:
    0

    DisturbedOne Member

    Set focus on keypress (newb)

    Focus is when the cursor of a TextBox is set to that TextBox.
    Like when you press Tab, the focus switches to the next Label/Button/TextBox
     
  11. Unread #6 - Mar 9, 2007 at 9:56 PM
  12. Skeletron
    Referrals:
    0

    Skeletron Guest

    Set focus on keypress (newb)

    There, you have to set keyprewiew to true for it to work. If you do this in a textbox then you don't.

    Sorry for the wait, I was busy with finishing up my semi-OCR.
     
  13. Unread #7 - Mar 9, 2007 at 11:03 PM
  14. ray230
    Referrals:
    0

    ray230 Guest

    Set focus on keypress (newb)


    OOOOHHHHHH so that's what it means!
     
  15. Unread #8 - Mar 9, 2007 at 11:17 PM
  16. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    Set focus on keypress (newb)

    doesn't work sorry Skeletron

    EDIT: This works, I guess I'll just make em press tab instead ;)

    Code:
        Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
            If e.KeyChar = Chr(Keys.Tab) Then
                txtSearch.Focus()
            End If
        End Sub
     
  17. Unread #9 - Mar 10, 2007 at 1:13 PM
  18. Skeletron
    Referrals:
    0

    Skeletron Guest

    Set focus on keypress (newb)

    Did you enable keypreview like I asked you to. And, that does work, when the textbox is not focused, but only on the form.

    If it does not work for you then you need to add some extra code for it to work.

    Oh, and it is this / not this \ one. The \ slash has a different chr then /.
     
  19. Unread #10 - Mar 14, 2007 at 3:19 AM
  20. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    Set focus on keypress (newb)

    I was asking for backslash =/
     
< [TUT] Pointers | Paper, Scissors, Rock -- Small problem, but still works >

Users viewing this thread
1 guest


 
 
Adblock breaks this site