Adblock breaks this site

Set focus on keypress (newb)

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

  1. Swan

    Swan When They Cry...
    Retired Global Moderator

    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner
    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.
     
  2. Skeletron

    Skeletron Guest

    Referrals:
    0
    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
     
  3. Swan

    Swan When They Cry...
    Retired Global Moderator

    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner
    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.
     
  4. ray230

    ray230 Guest

    Referrals:
    0
    Set focus on keypress (newb)

    What does focus mean?


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

    Newb Question.
     
  5. DisturbedOne

    DisturbedOne Member

    Joined:
    Jan 21, 2007
    Posts:
    54
    Referrals:
    0
    Sythe Gold:
    0
    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
     
  6. Skeletron

    Skeletron Guest

    Referrals:
    0
    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.
     
  7. ray230

    ray230 Guest

    Referrals:
    0
    Set focus on keypress (newb)


    OOOOHHHHHH so that's what it means!
     
  8. Swan

    Swan When They Cry...
    Retired Global Moderator

    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner
    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
     
  9. Skeletron

    Skeletron Guest

    Referrals:
    0
    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 /.
     
  10. Swan

    Swan When They Cry...
    Retired Global Moderator

    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner
    Set focus on keypress (newb)

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


 
 
Adblock breaks this site