📄 menucontrol.cs
字号:
}
else
{
// No window is maximized, so hide the buttons
if (_minButton.Visible)
{
_minButton.Hide();
_restoreButton.Hide();
_closeButton.Hide();
}
}
}
else
{
// No window is maximized, so hide the buttons
if ((_minButton != null) && _minButton.Visible)
{
_minButton.Hide();
_restoreButton.Hide();
_closeButton.Hide();
}
}
if (_direction == Direction.Horizontal)
{
int controlHeight = (rows + 1) * _rowHeight;
// Ensure the control is the correct height
if (this.Height != controlHeight)
this.Height = controlHeight;
}
else
{
int controlWidth = (rows + 1) * _rowWidth;
// Ensure the control is the correct width
if (this.Width != controlWidth)
this.Width = controlWidth;
}
}
}
protected void DrawCommand(int drawItem, bool tracked)
{
// Create a graphics object for drawing
using(Graphics g = this.CreateGraphics())
DrawSingleCommand(g, _drawCommands[drawItem] as DrawCommand, tracked);
}
internal void DrawSingleCommand(Graphics g, DrawCommand dc, bool tracked)
{
Rectangle drawRect = dc.DrawRect;
MenuCommand mc = dc.MenuCommand;
// Copy the rectangle used for drawing cell
Rectangle shadowRect = drawRect;
// Expand to right and bottom to cover the area used to draw shadows
shadowRect.Width += _shadowGap;
shadowRect.Height += _shadowGap;
// Draw background color over cell and shadow area to the right
g.FillRectangle(_backBrush, shadowRect);
if (!dc.Separator)
{
Rectangle textRect;
// Text rectangle size depends on type of draw command we are drawing
if (dc.Chevron)
{
// Create chevron drawing rectangle
textRect = new Rectangle(drawRect.Left + _lengthGap, drawRect.Top + _boxExpandUpper,
drawRect.Width - _lengthGap * 2, drawRect.Height - (_boxExpandUpper * 2));
}
else
{
// Create text drawing rectangle
textRect = new Rectangle(drawRect.Left + _lengthGap, drawRect.Top + _lengthGap,
drawRect.Width - _lengthGap * 2, drawRect.Height - _lengthGap * 2);
}
if (dc.Enabled)
{
// Draw selection
if (tracked)
{
Rectangle boxRect;
// Create the rectangle for box around the text
if (_direction == Direction.Horizontal)
{
boxRect = new Rectangle(textRect.Left - _boxExpandSides,
textRect.Top - _boxExpandUpper,
textRect.Width + _boxExpandSides * 2,
textRect.Height + _boxExpandUpper);
}
else
{
if (!dc.Chevron)
{
boxRect = new Rectangle(textRect.Left,
textRect.Top - _boxExpandSides,
textRect.Width - _boxExpandSides,
textRect.Height + _boxExpandSides * 2);
}
else
boxRect = textRect;
}
switch(_style)
{
case VisualStyle.IDE:
if (_selected)
{
// Fill the entire inside
g.FillRectangle(Brushes.White, boxRect);
g.FillRectangle(_controlLBrush, boxRect);
Color extraColor = Color.FromArgb(64, 0, 0, 0);
Color darkColor = Color.FromArgb(48, 0, 0, 0);
Color lightColor = Color.FromArgb(0, 0, 0, 0);
int rightLeft = boxRect.Right + 1;
int rightBottom = boxRect.Bottom;
if (_drawUpwards && (_direction == Direction.Horizontal))
{
// Draw the box around the selection area
using(Pen dark = new Pen(ControlPaint.Dark(_selectedBackColor)))
g.DrawRectangle(dark, boxRect);
if (dc.SubMenu)
{
// Right shadow
int rightTop = boxRect.Top;
int leftLeft = boxRect.Left + _shadowGap;
// Bottom shadow
int top = boxRect.Bottom + 1;
int left = boxRect.Left + _shadowGap;
int width = boxRect.Width + 1;
int height = _shadowGap;
Brush rightShadow;
Brush bottomLeftShadow;
Brush bottomShadow;
Brush bottomRightShadow;
// Decide if we need to use an alpha brush
if (_supportsLayered)
{
// Create brushes
rightShadow = new LinearGradientBrush(new Point(rightLeft, 9999),
new Point(rightLeft + _shadowGap, 9999),
darkColor, lightColor);
bottomLeftShadow = new LinearGradientBrush(new Point(left + _shadowGap, top - _shadowGap),
new Point(left, top + height),
extraColor, lightColor);
bottomRightShadow = new LinearGradientBrush(new Point(left + width - _shadowGap - 2, top - _shadowGap - 2),
new Point(left + width, top + height),
extraColor, lightColor);
bottomShadow = new LinearGradientBrush(new Point(9999, top),
new Point(9999, top + height),
darkColor, lightColor);
}
else
{
rightShadow = new SolidBrush(SystemColors.ControlDark);
bottomLeftShadow = rightShadow;
bottomShadow = rightShadow;
bottomRightShadow = rightShadow;
}
// Draw each part of the shadow area
g.FillRectangle(rightShadow, new Rectangle(rightLeft, rightTop, _shadowGap, rightBottom - rightTop + 1));
g.FillRectangle(bottomLeftShadow, left, top, _shadowGap, height);
g.FillRectangle(bottomRightShadow, left + width - _shadowGap, top, _shadowGap, height);
g.FillRectangle(bottomShadow, left + _shadowGap, top, width - _shadowGap * 2, height);
// Dispose of brush objects
if (_supportsLayered)
{
rightShadow.Dispose();
bottomLeftShadow.Dispose();
bottomShadow.Dispose();
bottomRightShadow.Dispose();
}
else
rightShadow.Dispose();
}
}
else
{
// Draw the box around the selection area
using(Pen dark = new Pen(ControlPaint.Dark(_selectedBackColor)))
g.DrawRectangle(dark, boxRect);
if (dc.SubMenu)
{
if (_direction == Direction.Horizontal)
{
// Remove the bottom line of the selection area
g.DrawLine(Pens.White, boxRect.Left, boxRect.Bottom, boxRect.Right, boxRect.Bottom);
g.DrawLine(_controlLPen, boxRect.Left, boxRect.Bottom, boxRect.Right, boxRect.Bottom);
int rightTop = boxRect.Top + _shadowYOffset;
Brush shadowBrush;
// Decide if we need to use an alpha brush
if (_supportsLayered && (_style == VisualStyle.IDE))
{
using(LinearGradientBrush topBrush = new LinearGradientBrush(new Point(rightLeft - _shadowGap, rightTop + _shadowGap),
new Point(rightLeft + _shadowGap, rightTop),
extraColor, lightColor))
{
g.FillRectangle(topBrush, new Rectangle(rightLeft, rightTop, _shadowGap, _shadowGap));
rightTop += _shadowGap;
}
shadowBrush = new LinearGradientBrush(new Point(rightLeft, 9999),
new Point(rightLeft + _shadowGap, 9999),
darkColor, lightColor);
}
else
shadowBrush = new SolidBrush(SystemColors.ControlDark);
g.FillRectangle(shadowBrush, new Rectangle(rightLeft, rightTop, _shadowGap, rightBottom - rightTop));
shadowBrush.Dispose();
}
else
{
// Remove the right line of the selection area
g.DrawLine(Pens.White, boxRect.Right, boxRect.Top, boxRect.Right, boxRect.Bottom);
g.DrawLine(_controlLPen, boxRect.Right, boxRect.Top, boxRect.Right, boxRect.Bottom);
int leftLeft = boxRect.Left + _shadowYOffset;
Brush shadowBrush;
// Decide if we need to use an alpha brush
if (_supportsLayered && (_style == VisualStyle.IDE))
{
using(LinearGradientBrush topBrush = new LinearGradientBrush(new Point(leftLeft + _shadowGap, rightBottom + 1 - _shadowGap),
new Point(leftLeft, rightBottom + 1 + _shadowGap),
extraColor, lightColor))
{
g.FillRectangle(topBrush, new Rectangle(leftLeft, rightBottom + 1, _shadowGap, _shadowGap));
leftLeft += _shadowGap;
}
shadowBrush = new LinearGradientBrush(new Point(9999, rightBottom + 1),
new Point(9999, rightBottom + 1 + _shadowGap),
darkColor, lightColor);
}
else
shadowBrush = new SolidBrush(SystemColors.ControlDark);
g.FillRectangle(shadowBrush, new Rectangle(leftLeft, rightBottom + 1, rightBottom - leftLeft - _shadowGap, _shadowGap));
shadowBrush.Dispose();
}
}
}
}
else
{
using (Pen selectPen = new Pen(_highlightBackDark))
{
// Draw the selection area in white so can alpha draw over the top
g.FillRectangle(Brushes.White, boxRect);
using (SolidBrush selectBrush = new SolidBrush(_highlightBackLight))
{
// Draw the selection area
g.FillRectangle(selectBrush, boxRect);
// Draw a border around the selection area
g.DrawRectangle(selectPen, boxRect);
}
}
}
break;
case VisualStyle.Plain:
if (_plainAsBlock)
{
using (SolidBrush selectBrush = new SolidBrush(_highlightBackDark))
g.FillRectangle(selectBrush, drawRect);
}
else
{
if (_selected)
{
using(Pen lighlight = new Pen(ControlPaint.LightLight(this.BackColor)),
dark = new Pen(ControlPaint.DarkDark(this.BackColor)))
{
g.DrawLine(dark, boxRect.Left, boxRect.Bottom, boxRect.Left, boxRect.Top);
g.DrawLine(dark, boxRect.Left, boxRect.Top, boxRect.Right, boxRect.Top);
g.DrawLine(lighlight, boxRect.Right, boxRect.Top, boxRect.Right, boxRect.Bottom);
g.DrawLine(lighlight, boxRect.Right, boxRect.Bottom, boxRect.Left, boxRect.Bottom);
}
}
else
{
using(Pen lighlight = new Pen(ControlPaint.LightLight(this.BackColor)),
dark = new Pen(ControlPaint.DarkDark(this.BackColor)))
{
g.DrawLine(lighlight, boxRect.Left, boxRect.Bottom, boxRect.Left, boxRect.Top);
g.DrawLine(lighlight, boxRect.Left, boxRect.Top, boxRect.Right, boxRect.Top);
g.DrawLine(dark, boxRect.Right, boxRect.Top, boxRect.Right, boxRect.Bottom);
g.DrawLine(dark, boxRect.Right, boxRect.Bottom, boxRect.Left, boxRect.Bottom);
}
}
}
break;
}
}
}
if (dc.Chevron)
{
// Draw the chevron image in the centre of the text area
int yPos = drawRect.Top;
int xPos = drawRect.X + ((drawRect.Width - _chevronLength) / 2);
// When selected...
if (_selected)
{
// ...offset down and to the right
xPos += 1;
yPos += 1;
}
g.DrawImage(_menuImages.Images[_chevronIndex], xPos, yPos);
}
else
{
// Left align the text drawing on a single line centered vertically
// and process the & character to be shown as an underscore on next character
StringFormat format = new StringFormat();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -