/// <summary> /// This method Draws the picture associated with a MenuItem /// </summary> private static void DrawItemPicture(System.Windows.Forms.DrawItemEventArgs e, MenuItem mi) { const int MAX_PIC_SIZE = 16; // Get the Item's picture Image img = OfficeMenus.GetItemPicture(mi); // check to see if the Item has a picture, if none, Ignore if (img != null) { // if the size exceeds the maximum picture's size, fix it int width = img.Width > MAX_PIC_SIZE ? MAX_PIC_SIZE : img.Width; int height = img.Height > MAX_PIC_SIZE ? MAX_PIC_SIZE : img.Height; // set the picture coordinates int x = e.Bounds.X + 2; int y = e.Bounds.Y + ((e.Bounds.Height - height) / 2); // create the picture rectangle Rectangle rect = new Rectangle(x, y, width, height); // Now check the items state, if enabled just draw the picture // if not enabled, make a water mark and draw it. if (mi.Enabled) { // draw the image e.Graphics.DrawImage(img, x, y, width, height); } else { // make water mark of the picture ColorMatrix myColorMatrix = new ColorMatrix(); myColorMatrix.Matrix00 = 1.00f; // Red myColorMatrix.Matrix11 = 1.00f; // Green myColorMatrix.Matrix22 = 1.00f; // Blue myColorMatrix.Matrix33 = 1.30f; // alpha myColorMatrix.Matrix44 = 1.00f; // w // Create an ImageAttributes object and set the color matrix. ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetColorMatrix(myColorMatrix); // draw the image e.Graphics.DrawImage(img, rect, 0, 0, width, height, GraphicsUnit.Pixel, imageAttr); } } }
/// <summary> /// This method draws a CheckBox for a MenuItem /// </summary> private static void DrawCheckBox(System.Windows.Forms.DrawItemEventArgs e, MenuItem mi) { // Define the CheckBox size int cbSize = Globals.PIC_AREA_SIZE - 5; // set the smoothing mode to anti alias e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; // the main rectangle Rectangle rect = new Rectangle(e.Bounds.X + 1, e.Bounds.Y + ((e.Bounds.Height - cbSize) / 2), cbSize, cbSize); // construct the drawing pen Pen pen = new Pen(Color.Black, 1.7f); // fill the rectangle if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { e.Graphics.FillRectangle(new SolidBrush(Globals.DarkCheckBoxColor), rect); } else { e.Graphics.FillRectangle(new SolidBrush(Globals.CheckBoxColor), rect); } // draw borders e.Graphics.DrawRectangle(new Pen(Globals.MenuDarkColor), rect); // Check to see if the menuItem has a picture // if Yes, Do not draw the check mark; else, Draw it Bitmap img = OfficeMenus.GetItemPicture(mi); if (img == null) { // Draw the check mark e.Graphics.DrawLine(pen, e.Bounds.X + 7, e.Bounds.Y + 10, e.Bounds.X + 10, e.Bounds.Y + 14); e.Graphics.DrawLine(pen, e.Bounds.X + 10, e.Bounds.Y + 14, e.Bounds.X + 15, e.Bounds.Y + 9); } }