Results 1 to 2 of 2

Thread: Picturebox as a button?

  1. #1

    Thread Starter
    Junior Member ryanguy426's Avatar
    Join Date
    May 2013
    Posts
    22

    Question Picturebox as a button?

    Hey all me again!

    Trying to give my web browser a facelift so it doesn't look like cat crap, but I can't get the picturebox to work as a button.

    Code:
    Private Sub PictureBox2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles PictureBox2.KeyDown
            If e.KeyCode = Keys.Enter Then
                PictureBox2.PerformClick()
            End If
        End Sub
    Doesn't seem to work... throws an error saying: "'PerformClick' is not a member of 'System.Windows.Forms.PictureBox'."

    Any way to fix this, or make it work AT ALL?

    Thank you for taking your time to read my post.

  2. #2
    Hyperactive Member
    Join Date
    Apr 2011
    Location
    England
    Posts
    421

    Re: Picturebox as a button?

    Try using the click event instead of the KeyDown event:
    VB.NET Code:
    1. Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click
    2.     MessageBox.Show("I was clicked.")
    3. End Sub
    If you want to simulate a click when someone presses a key on the picturebox then you would do so like this (you would need the above code in your project too):
    VB.NET Code:
    1. Private Sub PictureBox2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles PictureBox2.KeyDown
    2.     If e.KeyCode = Keys.Enter Then
    3.         PictureBox2_Click(PictureBox2, New MouseEventArgs(Windows.Forms.MouseButtons.Left, 1, MousePosition.X, MousePosition.Y, 0))
    4.     End If
    5. End Sub

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