I have a custom button (public partial class QButton : Control
) that has the following code to change its own checked-state when a user clicks on it:
protected override void OnMouseClick(MouseEventArgs e)
{
if (e.Button != System.Windows.Forms.MouseButtons.Left)
{
base.OnMouseClick(e);
return;
}
Status tmp = m_status;
if (m_status.HasFlag(Status.Checked))
m_status &= ~Status.Checked;
else
m_status |= Status.Checked;
if (tmp != m_status)
Invalidate();
base.OnMouseClick(e);
}
That part is working well. When using this button in a form, I connect the events in the form like this:
public void attach(Control.ControlCollection c)
{
/* ... */
m_Button.Click += OnEnable;
}
protected void OnEnable(object sender, EventArgs e)
{
/* the following still returns the old state as buttons OnMouseClick hasnt yet been called */
m_enabled = m_Button.Checked;
updateEnableState();
}
So what I want is that my form gets notified of the click and can do some magic. The problem is that the form gets notified before my button gets the notification, so first the forms OnEnable
-method gets called and then the Buttons OnMouseClick
-method gets called.
How do I notify the button of a sucessfull click-event before the form gets involved?