is it possible to make a picturebox the acceptbutton?
i tried this in form load

Dim picturebox1 As New Button
        Me.AcceptButton = picturebox1

is there a way i could do this?

6 Years
Discussion Span
Last Post by eikal

A bit confusing to understand, but since an Accept Button is like a Submit button on a Form, pressing the Enter key in any of the fields should press the Submit Button, in this case a PictureBox.

If so, see if the following code sample helps.

'//---------  Pre-requisites: 1 PictureBox, 3 TextBoxes. ---------\\
Public Class Form1

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
        MsgBox("PictureBox Clicked.", MsgBoxStyle.Information)
    End Sub

    '// use one event for multiple controls.
    Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) _
                                Handles TextBox1.KeyUp, TextBox2.KeyUp, TextBox3.KeyUp
        If e.KeyCode = Keys.Enter Then PictureBox1_Click(sender, e) '// call the event procedure.
    End Sub
End Class

So you want to raise the Picturebox1.Click event when the user presses the enter key?

Why not make a hidden button, make it your "accept button" and then use the following code

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        PictureBox1_Click(sender, e)
    End Sub

Or just put the image in the .Image property of the button and clean the .text.

Resize the button to the image size.

Hope this helps


ahhh ok! you guys are smart! XD i didnt think about making a hidden button. good simple fix. its not important im just bored and made a stylish button using a picturebox.

EDIT-- the hidden button didnt work, but i followed code orders code and trigged the picturebox when enter key was pressed when the textbox has focus

Edited by eikal: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.