6 Replies - 237 Views - Last Post: 15 July 2014 - 12:14 PM Rate Topic: -----

#1 petkov117  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-July 14

bind key to a button problem

Posted 14 July 2014 - 04:07 PM

hi i am trying to bind a lot of keys to a lot of buttons but there is a problem it does not work i try only with one or to buttons but now
  
  Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        Select Case e.KeyCode
            Case Keys.M
                Button1.PerformClick()
            Case Keys.N
                Button2.PerformClick()

        End Select
    End Sub

this is the code which i try but it doesn't work can somebody help me

Is This A Good Question/Topic? 0
  • +

Replies To: bind key to a button problem

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3177
  • View blog
  • Posts: 10,638
  • Joined: 12-December 12

Re: bind key to a button problem

Posted 14 July 2014 - 04:09 PM

Make sure that you have set the form's KeyPreview property to true so that the form can receive key events.

Then put a MessageBox in that code to check that it runs at all.
Was This Post Helpful? 0
  • +
  • -

#3 petkov117  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-July 14

Re: bind key to a button problem

Posted 14 July 2014 - 04:21 PM

can you give me example becouse i have no idea what are you talking about thank you
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3177
  • View blog
  • Posts: 10,638
  • Joined: 12-December 12

Re: bind key to a button problem

Posted 14 July 2014 - 04:46 PM

There is a Properties window. Click on the form area and examine its properties. Set its KeyPreview property to True.
Was This Post Helpful? 1
  • +
  • -

#5 petkov117  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-July 14

Re: bind key to a button problem

Posted 14 July 2014 - 11:27 PM

it still does not work
Was This Post Helpful? 0
  • +
  • -

#6 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 197
  • View blog
  • Posts: 690
  • Joined: 01-February 13

Re: bind key to a button problem

Posted 15 July 2014 - 12:07 PM

Hi,
It should work as long as your Form has focus and you have the Forms KeyPreview set to True. Perhaps you are trying to capture the keys when the Form is in the Background behind other windows or maybe when it is minimized? You would need to use a whole different approach if that is what your trying to do.

Please explain exactly what you are doing so we can assist you to fix your problem. :rolleyes:
Was This Post Helpful? 0
  • +
  • -

#7 ybadragon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 177
  • View blog
  • Posts: 1,087
  • Joined: 11-May 12

Re: bind key to a button problem

Posted 15 July 2014 - 12:14 PM

also put a breakpoint in your code to make sure you are actually hitting it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1