mardi 3 mars 2015

Override AcceptButton Setting On Inherited Windows Form

I am working on a winforms application. The form I am working on inherits a base form. On the base form the AcceptButton property is set to cmdOK (basically the save and exit button). This is required behaviour.


However, the form I am working on has a number of dropdownlist and while the focus is on them I need to change the behaviour of the enter key.


For example if the focus is on cboTags and Enter is press I need to call cmdAddTag_Click, if shift + Enter is press I need to call cmdRemoveTag_Click. I have added the following code:



private void cboTags_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter && e.Modifiers == Keys.Shift)
{
cmdRemoveTag_Click(new object(), new EventArgs());
}
else if (e.KeyCode == Keys.Enter)
{
cmdAddTag_Click(new object(), new EventArgs());
}
}


When I tested it and found the window closed I realised the AcceptButton property had been set on the inherited form. I cannot find a way round it.


Aucun commentaire:

Enregistrer un commentaire