⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainmenuitemdrawing.cs

📁 该即时通讯系统系统能够实现像QQ一样的通讯功能
💻 CS
字号:
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

namespace LanMsg.Controls
{
	/// <summary>
	/// This Class Has methods to draw Main MenuItem
	/// </summary>
	public class MainMenuItemDrawing
	{
		/// <summary>
		/// The main method for drawing the main MenuItems
		/// </summary>
		public static void DrawMenuItem(System.Windows.Forms.DrawItemEventArgs e, MenuItem mi)
		{

			// Check the state of the menuItem
			if ( (e.State & DrawItemState.HotLight) == DrawItemState.HotLight ) {
				// Draw Hover rectangle
				DrawHoverRect(e, mi);
			} 
			else if ( (e.State & DrawItemState.Selected) == DrawItemState.Selected ) {
				// Draw selection rectangle
				DrawSelectionRect(e, mi);
			} else {
				// if no selection, just draw space
				Rectangle rect = new Rectangle(e.Bounds.X, 
					e.Bounds.Y, 
					e.Bounds.Width, 
					e.Bounds.Height -1);

				e.Graphics.FillRectangle(new SolidBrush(Globals.MainColor), rect);
				e.Graphics.DrawRectangle(new Pen(Globals.MainColor), rect);
			}
			
			// Create stringFormat object
			StringFormat sf = new StringFormat();

			// set the Alignment to center
			sf.LineAlignment = StringAlignment.Center;
			sf.Alignment = StringAlignment.Center;

			// Draw the text
			e.Graphics.DrawString(mi.Text, 
				Globals.menuFont, 
				new SolidBrush(Globals.TextColor), 
				e.Bounds, 
				sf);	
		}

		/// <summary>
		/// Draws the hover rectangle in case of a mouse is hovering 
		/// </summary>
		private static void DrawHoverRect(System.Windows.Forms.DrawItemEventArgs e, MenuItem mi)
		{
			// Create the hover rectangle
			Rectangle rect = new Rectangle(e.Bounds.X, 
				e.Bounds.Y + 1, 
				e.Bounds.Width, 
				e.Bounds.Height - 2);

			// Create the hover brush
			Brush b = new LinearGradientBrush(rect, 
				Color.White, 
				Globals.CheckBoxColor,
				90f, false);

			// Fill the rectangle
			e.Graphics.FillRectangle(b, rect);

			// Draw borders
			e.Graphics.DrawRectangle(new Pen(Color.Black), rect);
		}

		/// <summary>
		/// Draws a selection rectangle
		/// </summary>
		private static void DrawSelectionRect(System.Windows.Forms.DrawItemEventArgs e, MenuItem mi)
		{
			// Create the selection rectangle
			Rectangle rect = new Rectangle(e.Bounds.X, 
				e.Bounds.Y + 1, 
				e.Bounds.Width, 
				e.Bounds.Height - 2);

			// Create the selectino brush
			Brush b = new LinearGradientBrush(rect, 
				Globals.MenuBgColor, 
				Globals.MenuDarkColor2,
				90f, false);

			// fill the rectangle
			e.Graphics.FillRectangle(b, rect);

			// Draw borders
			e.Graphics.DrawRectangle(new Pen(Color.Black), rect);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -