Tema: Re: .NET Default button dilemele [solved]
Autorius: Jornada Del Muerto
Data: 2010-05-24 16:09:21
Jei kam reikia kodas kaip tai padaryt:
public class UclBase : UserControl
{
#region Attributes
private IButtonControl _AcceptButton = null;
private IButtonControl _CancelButton = null;
#endregion
#region properties
[Description ("Gets or sets the button on the form that is clicked when the user presses the ENTER key.")]
public IButtonControl AcceptButton
{
get { return _AcceptButton; }
set { _AcceptButton = value; }
}
[Description ("Gets or sets the button control that is clicked when the user presses the ESC key.")]
public IButtonControl CancelButton
{
get { return _CancelButton; }
set { _CancelButton = value; }
}
#region Overrides
protected override bool ProcessCmdKey (ref Message msg, Keys keyData)
{
if (keyData == Keys.Enter &&
_AcceptButton != null)
{
_AcceptButton.PerformClick ();
return true;
}
else if (keyData == Keys.Escape &&
_CancelButton != null)
{
_CancelButton.PerformClick ();
return true;
}
return base.ProcessCmdKey (
ref msg, keyData);
}
}
#endregion