Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

reacting to keyup?!

Joe2003Joe2003 Posts: 92Member
Hey

I have a pannel, all I want to do is if the user presses the up key I want a textbox to appear that says "UP", if they press down a textbox to appear that says "DOWN" and so on for left and right.

is this possible, I have been trying to use the keyup event handler but I cant get it to work.

cheers

Joel


Comments

  • lionblionb Posts: 1,688Member ✭✭
    : Hey
    :
    : I have a pannel, all I want to do is if the user presses the up key I want a textbox to appear that says "UP", if they press down a textbox to appear that says "DOWN" and so on for left and right.
    :
    : is this possible, I have been trying to use the keyup event handler but I cant get it to work.
    :
    : cheers
    :
    : Joel
    :
    [code]
    Private Sub Form_Load()
    Text1.Visible = False
    End Sub

    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then 'left button pressed
    Text1.Text = "DOWN"
    Text1.Visible = True
    End If
    End Sub

    Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then 'left button pressed
    Text1.Text = "UP"
    Text1.Visible = True
    End If

    End Sub
    [/code]


  • Mike_AB1Mike_AB1 Posts: 49Member
    : Hey
    :
    : I have a pannel, all I want to do is if the user presses the up key I want a textbox to appear that says "UP", if they press down a textbox to appear that says "DOWN" and so on for left and right.
    :
    : is this possible, I have been trying to use the keyup event handler but I cant get it to work.
    :
    : cheers
    :
    : Joel
    :
    :
    :

    Try this:

    [Code]
    Private Sub Form_Load()
    '''This way no matter which control has focus - all the key events will be processed by the form
    Form1.KeyPreview = True '''you can set this in the form properties
    End Sub
    Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    With Text1
    Select Case KeyCode
    Case vbKeyUp
    .Text = "Up"
    Case vbKeyDown
    .Text = "Down"
    Case vbKeyLeft
    .Text = "Left"
    Case vbKeyRight
    .Text = "Right"
    Case Else
    .Text = ""
    End Select
    End With
    End Sub
    [/Code]

    Mike
Sign In or Register to comment.