protected override void OnClick(EventArgs e)
{
// Only if associated view is enabled to we perform an action
if (GetViewEnabled())
{
// If we do not provide an inert form
if (!KryptonForm.InertForm)
{
// Only if the mouse is still within the button bounds do we perform action
MouseEventArgs mea = (MouseEventArgs)e;
if (GetView().ClientRectangle.Contains(mea.Location))
{
PropertyInfo pi = typeof(Form).GetProperty("CloseReason",
BindingFlags.Instance |
BindingFlags.SetProperty |
BindingFlags.NonPublic);
// Update form with the reason for the close
pi.SetValue(KryptonForm, CloseReason.UserClosing, null);
// Convert screen position to LPARAM format of WM_SYSCOMMAND message
Point screenPos = Control.MousePosition;
IntPtr lParam = (IntPtr)(PI.MAKELOWORD(screenPos.X) |
PI.MAKEHIWORD(screenPos.Y));
// Request the form be closed down
KryptonForm.SendSysCommand(PI.SC_CLOSE, lParam);
// Let base class fire any other attached events
base.OnClick(e);
}
}
}
}