📄 vsnetstyle.cs
字号:
using System;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Drawing;
using System.Windows.Forms.Design;
using System.Configuration;
using System.Collections;
using System.Windows.Forms;
namespace WindowsApplication.MenuStyle
{
public class VSNetStyle: System.Windows.Forms.MainMenu
{
public VSNetStyle()
{
}
static Color bgcolor = Color.FromArgb(246, 246, 246);
static Color ibgcolor = Color.FromArgb(202, 202, 202);
static Color sbcolor = Color.FromArgb(173, 173, 209);
static Color sbbcolor = Color.FromArgb( 0, 0, 128);
static int TEXTSTART = 20;
public void DrawCheckmark(Graphics g, Rectangle bounds, bool selected)
{
ControlPaint.DrawMenuGlyph(g, new Rectangle(bounds.X + 2, bounds.Y + 2, 14, 14), MenuGlyph.Checkmark);
}
public void DrawIcon(Graphics g, Image icon, Rectangle bounds, bool selected, bool enabled, bool ischecked)
{
if (enabled)
{
if (selected)
{
ControlPaint.DrawImageDisabled(g, icon, bounds.Left + 2, bounds.Top + 2, Color.Black);
g.DrawImage(icon, bounds.Left + 1, bounds.Top + 1);
}
else
{
g.DrawImage(icon, bounds.Left + 2, bounds.Top + 2);
}
}
else
ControlPaint.DrawImageDisabled(g, icon, bounds.Left + 2, bounds.Top + 2, SystemColors.HighlightText);
}
public void DrawSeparator(Graphics g, Rectangle bounds)
{
int y = bounds.Y + bounds.Height / 2;
g.DrawLine(new Pen(SystemColors.ControlDark), bounds.X + SystemInformation.SmallIconSize.Width + 7, y, bounds.X + bounds.Width - 2, y);
}
public void DrawBackground(Graphics g, Rectangle bounds, DrawItemState state, bool toplevel, bool hasicon)
{
bool selected = (state & DrawItemState.Selected) > 0;
if (selected || ((state & DrawItemState.HotLight) > 0))
{
if (toplevel && selected)
{ // draw toplevel, selected menuitem
g.FillRectangle(new SolidBrush(ibgcolor), bounds);
ControlPaint.DrawBorder3D(g, bounds.Left, bounds.Top, bounds.Width, bounds.Height, Border3DStyle.Flat, Border3DSide.Top | Border3DSide.Left | Border3DSide.Right);
}
else
{ // draw menuitem, selected OR toplevel, hotlighted
g.FillRectangle(new SolidBrush(sbcolor), bounds);
g.DrawRectangle(new Pen(sbbcolor), bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1);
}
}
else
{
if (!toplevel)
{ // draw menuitem, unselected
g.FillRectangle(new SolidBrush(ibgcolor), bounds);
bounds.X += SystemInformation.SmallIconSize.Width + 5;
bounds.Width -= SystemInformation.SmallIconSize.Width + 5;
g.FillRectangle(new SolidBrush(bgcolor), bounds);
}
else
{
// draw toplevel, unselected menuitem
g.FillRectangle(SystemBrushes.Menu, bounds);
}
}
}
public void DrawMenuText(Graphics g, Rectangle bounds, string text, string shortcut, bool enabled, bool toplevel, DrawItemState state)
{
StringFormat stringformat = new StringFormat();
stringformat.HotkeyPrefix = ((state & DrawItemState.NoAccelerator) > 0) ? HotkeyPrefix.Hide : HotkeyPrefix.Show;
int textwidth = (int)(g.MeasureString(text, SystemInformation.MenuFont).Width);
int x = toplevel ? bounds.Left + (bounds.Width - textwidth) / 2: bounds.Left + TEXTSTART;
int y = bounds.Top + 2;
Brush brush = null;
if (!enabled)
brush = new SolidBrush(Color.FromArgb(120, SystemColors.MenuText));
else
brush = new SolidBrush(Color.Black);
g.DrawString(text, SystemInformation.MenuFont, brush, x, y, stringformat);
g.DrawString(shortcut, SystemInformation.MenuFont, brush, bounds.Left + 130, bounds.Top + 2, stringformat);
}
// protected override void OnMeasureItem(MeasureItemEventArgs e)
//
// {
//
// base.OnMeasureItem(e);
//
//
// // make shortcut text 省略这部分代码。
//
// if (menustyle != IconMenuStyle.Standard)
//
// {
//
// if (Text == "-")
//
// {
//
// e.ItemHeight = 8;
//
// e.ItemWidth = 4;
//
// return;
//
// }
//
// int textwidth = (int)(e.Graphics.MeasureString(Text + shortcuttext, SystemInformation.MenuFont).Width);
//
// e.ItemHeight = SystemInformation.MenuHeight;
//
// if (Parent == Parent.GetMainMenu())
//
// e.ItemWidth = textwidth - 5; // 5 is a magic number
//
// else
//
// e.ItemWidth = Math.Max(160, textwidth + 50);
//
// }
//
// }
// protected override void OnDrawItem(DrawItemEventArgs e)
//
// {
//
// base.OnDrawItem(e);
//
// Graphics g = e.Graphics;
//
// Rectangle bounds = e.Bounds;
//
// bool selected = (e.State & DrawItemState.Selected) > 0;
//
// bool toplevel = (Parent == Parent.GetMainMenu());
//
// bool hasicon = Icon != null;
//
// style.DrawBackground(g, bounds, e.State, toplevel, hasicon);
// if (hasicon)
// style.DrawIcon(g, Icon, bounds, selected, Enabled, Checked);
// else
// if (Checked)
// style.DrawCheckmark(g, bounds, selected);
// if (Text == "-")
// {
// style.DrawSeparator(g, bounds);
// }
// else
// {
// style.DrawMenuText(g, bounds, Text, shortcuttext, Enabled, toplevel, e.State);
// }
// }
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -