-2

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.

Vnz Dichoso
  • 182
  • 1
  • 2
  • 11

2 Answers2

5

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);
}
Trevor Elliott
  • 11,292
  • 11
  • 63
  • 102
0

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.

Ankit
  • 38
  • 1
  • 7