C# Picture Box as Accept Button of a Form

953 Views Asked by At

Is there a way to set a picture box as the accept button of a winform? I tried to set it up on the form properties but it doesn't show up. Thanks for the answers.

2

There are 2 best solutions below

0
Trevor Elliott On

No, a Button is an IButtonControl and a PictureBox is not. The Form.AcceptButton property is typed as an IButtonControl.

You can override ProcessCmdKey on the Form to intercept the Enter key as an alternative:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    if (keyData == Keys.Enter)
    {
        // call your function instead if you want to do some processing first
        Close();
        return true; // return true to intercept the key press
    }

    return base.ProcessCmdKey(ref msg, keyData);
}
0
Ankit On

it has to be button to be an "accept button of a winform" try setting backgroundimage property of a button as desired image and then set it as accept button of form.