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.
Asked
Active
Viewed 946 times
-2
-
Why? And what do you mean "it doesn't show up"? You have to have the "Accepted Button" control on the form and then use it in the property. – gunr2171 Oct 17 '13 at 19:58
-
Unclear at the moment, What are you trying to acheive? – Sriram Sakthivel Oct 17 '13 at 19:59
-
1Property is not named "AcceptPictureBox" it is "AcceptButton"! it has to be a button. More precise `IButtonControl` – Sriram Sakthivel Oct 17 '13 at 20:01
-
An old hack I've been using for years is to add a button set it as AcceptButton and put it at location -100,-100. User won't know it's there but Enter will work – Alexandre Rondeau Oct 17 '13 at 20:01
-
I've been trying to set a picture box as the AcceptButton of the form. Trevor Elliot's had already answered my question. Thanks for replies. – Vnz Dichoso Oct 17 '13 at 20:22
2 Answers
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