private void PressMenuCheckBox(bool keyboard)
{
if (keyboard)
{
_menuCheckBox.ViewDrawContent.ElementState = PaletteState.Pressed;
PerformNeedPaint();
Application.DoEvents();
}
// Should we automatically try and close the context menu stack
if (_menuCheckBox.KryptonContextMenuCheckBox.AutoClose)
{
// Is the menu capable of being closed?
if (_menuCheckBox.CanCloseMenu)
{
// Ask the original context menu definition, if we can close
CancelEventArgs cea = new CancelEventArgs();
_menuCheckBox.Closing(cea);
if (!cea.Cancel)
{
// Close the menu from display and pass in the item clicked as the reason
_menuCheckBox.Close(new CloseReasonEventArgs(ToolStripDropDownCloseReason.ItemClicked));
}
}
}
// Do we need to automatically change the checked/checkstate?
if (_menuCheckBox.KryptonContextMenuCheckBox.AutoCheck)
{
// Grab current state from command or ourself
CheckState state = (_menuCheckBox.KryptonContextMenuCheckBox.KryptonCommand == null ?
_menuCheckBox.KryptonContextMenuCheckBox.CheckState :
_menuCheckBox.KryptonContextMenuCheckBox.KryptonCommand.CheckState);
// Change state based on the current state
switch (state)
{
case CheckState.Unchecked:
state = CheckState.Checked;
break;
case CheckState.Checked:
state = (_menuCheckBox.KryptonContextMenuCheckBox.ThreeState ? CheckState.Indeterminate : CheckState.Unchecked);
break;
case CheckState.Indeterminate:
state = CheckState.Unchecked;
break;
}
// Update correct target with new state
if (_menuCheckBox.KryptonContextMenuCheckBox.KryptonCommand != null)
{
_menuCheckBox.KryptonContextMenuCheckBox.KryptonCommand.CheckState = state;
}
else
{
_menuCheckBox.KryptonContextMenuCheckBox.CheckState = state;
}
// Update visual appearance to reflect new state
_menuCheckBox.ViewDrawCheckBox.CheckState = state;
}
Click?.Invoke(this, EventArgs.Empty);
if (keyboard)
{
UpdateTarget();
PerformNeedPaint();
}
}