📄 menucontrol.cs
字号:
if (value != _highlightTextColor)
{
_highlightTextColor = value;
_defaultHighlightTextColor = (value == SystemColors.MenuText);
Recalculate();
Invalidate();
}
}
}
private bool ShouldSerializeHighlightTextColor()
{
return _highlightTextColor != SystemColors.HighlightText;
}
[Category("Appearance")]
public Color SelectedBackColor
{
get { return _selectedBackColor; }
set
{
if (value != _selectedBackColor)
{
DefineSelectedBackColors(value);
_defaultSelectedBackColor = (value == SystemColors.Control);
Recalculate();
Invalidate();
}
}
}
private bool ShouldSerializeSelectedBackColor()
{
return _selectedBackColor != SystemColors.Control;
}
[Category("Appearance")]
public Color SelectedTextColor
{
get { return _selectedTextColor; }
set
{
if (value != _selectedTextColor)
{
_selectedTextColor = value;
_defaultSelectedTextColor = (value == SystemColors.MenuText);
Recalculate();
Invalidate();
}
}
}
private bool ShouldSerializeSelectedTextColor()
{
return _selectedTextColor != SystemColors.MenuText;
}
[Category("Appearance")]
public Color PlainSelectedTextColor
{
get { return _plainSelectedTextColor; }
set
{
if (value != _plainSelectedTextColor)
{
_plainSelectedTextColor = value;
_defaultPlainSelectedTextColor = (value == SystemColors.ActiveCaptionText);
Recalculate();
Invalidate();
}
}
}
private bool ShouldSerializePlainSelectedTextColor()
{
return _plainSelectedTextColor != SystemColors.ActiveCaptionText;
}
[Category("Appearance")]
[DefaultValue(false)]
public bool PlainAsBlock
{
get { return _plainAsBlock; }
set
{
if (_plainAsBlock != value)
{
_plainAsBlock = value;
Recalculate();
Invalidate();
}
}
}
[Category("Appearance")]
[DefaultValue(false)]
public bool MultiLine
{
get { return _multiLine; }
set
{
if (_multiLine != value)
{
_multiLine = value;
Recalculate();
Invalidate();
}
}
}
[Category("Appearance")]
public Direction Direction
{
get { return _direction; }
set
{
if (_direction != value)
{
_direction = value;
Recalculate();
Invalidate();
}
}
}
[Category("Behaviour")]
[DefaultValue(true)]
public bool RememberExpansion
{
get { return _rememberExpansion; }
set { _rememberExpansion = value; }
}
[Category("Behaviour")]
[DefaultValue(true)]
public bool ExpandAllTogether
{
get { return _expandAllTogether; }
set { _expandAllTogether = value; }
}
[Category("Behaviour")]
[DefaultValue(true)]
public bool DeselectReset
{
get { return _deselectReset; }
set { _deselectReset = value; }
}
[Category("Behaviour")]
[DefaultValue(true)]
public bool HighlightInfrequent
{
get { return _highlightInfrequent; }
set { _highlightInfrequent = value; }
}
public override DockStyle Dock
{
get { return base.Dock; }
set
{
base.Dock = value;
switch(value)
{
case DockStyle.None:
_direction = Direction.Horizontal;
break;
case DockStyle.Top:
case DockStyle.Bottom:
this.Height = 0;
_direction = Direction.Horizontal;
break;
case DockStyle.Left:
case DockStyle.Right:
this.Width = 0;
_direction = Direction.Vertical;
break;
}
Recalculate();
Invalidate();
}
}
[Category("Animate")]
[DefaultValue(typeof(Animate), "System")]
public Animate Animate
{
get { return _animate; }
set { _animate = value; }
}
[Category("AnimateTime")]
public int AnimateTime
{
get { return _animateTime; }
set { _animateTime = value; }
}
[Category("AnimateStyle")]
public Animation AnimateStyle
{
get { return _animateStyle; }
set { _animateStyle = value; }
}
[Category("Behaviour")]
[DefaultValue(null)]
public Form MdiContainer
{
get { return _mdiContainer; }
set
{
if (_mdiContainer != value)
{
if (_mdiContainer != null)
{
// Unsubclass from MdiClient and then remove object reference
_clientSubclass.ReleaseHandle();
_clientSubclass = null;
// Remove registered events
_mdiContainer.MdiChildActivate -= new EventHandler(OnMdiChildActivate);
RemovePendantButtons();
}
_mdiContainer = value;
if (_mdiContainer != null)
{
CreatePendantButtons();
foreach(Control c in _mdiContainer.Controls)
{
MdiClient client = c as MdiClient;
if (client != null)
{
// We need to subclass the MdiClient to prevent any attempt
// to change the menu for the container Form. This prevents
// the system from automatically adding the pendant.
_clientSubclass = new MdiClientSubclass();
_clientSubclass.AssignHandle(client.Handle);
}
}
// Need to be informed of the active child window
_mdiContainer.MdiChildActivate += new EventHandler(OnMdiChildActivate);
}
}
}
}
protected void DefineColors()
{
// Define starting text colors
_defaultTextColor = true;
_defaultHighlightTextColor = true;
_defaultSelectedTextColor = true;
_defaultPlainSelectedTextColor = true;
_textColor = SystemColors.MenuText;
_highlightTextColor = SystemColors.MenuText;
_selectedTextColor = SystemColors.MenuText;
_plainSelectedTextColor = SystemColors.ActiveCaptionText;
// Define starting back colors
_defaultBackColor = true;
_defaultHighlightBackColor = true;
_defaultSelectedBackColor = true;
base.BackColor = SystemColors.Control;
_backBrush = new SolidBrush(base.BackColor);
_highlightBackColor = SystemColors.Highlight;
DefineHighlightBackColors(SystemColors.Highlight);
DefineSelectedBackColors(SystemColors.Control);
}
public void ResetColors()
{
this.BackColor = SystemColors.Control;
this.TextColor = SystemColors.MenuText;
this.HighlightBackColor = SystemColors.Highlight;
this.HighlightTextColor = SystemColors.MenuText;
this.SelectedBackColor = SystemColors.Control;
this.SelectedTextColor = SystemColors.MenuText;
}
protected void DefineFont(Font newFont)
{
base.Font = newFont;
_breadthGap = (this.Font.Height / 3) + 1;
// Calculate the initial height/width of the control
_rowWidth = _rowHeight = this.Font.Height + _breadthGap * 2 + 1;
}
protected void DefineSelectedBackColors(Color baseColor)
{
_selectedBackColor = baseColor;
_controlLPen = new Pen(Color.FromArgb(200, baseColor));
_controlLBrush = new SolidBrush(Color.FromArgb(200, baseColor));
}
protected void DefineHighlightBackColors(Color baseColor)
{
_highlightBackColor = baseColor;
if (_defaultHighlightBackColor)
{
_highlightBackDark = SystemColors.Highlight;
_highlightBackLight = Color.FromArgb(70, _highlightBackDark);
}
else
{
_highlightBackDark = ControlPaint.Dark(baseColor);
_highlightBackLight = baseColor;
}
}
public virtual void OnSelected(MenuCommand mc)
{
// Any attached event handlers?
if (Selected != null)
Selected(mc);
}
public virtual void OnDeselected(MenuCommand mc)
{
// Any attached event handlers?
if (Deselected != null)
Deselected(mc);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -