private void DrawMainMenu(Graphics graphics, Rectangle dest, DrawItemState state) { if ((state & DrawItemState.HotLight) == DrawItemState.HotLight) { graphics.FillRectangle(new SolidBrush(selectedGradientLeft), dest.X + 1, dest.Y, dest.Width - 1, dest.Height - 1); graphics.DrawRectangle(new Pen(selectedBorder), dest.X + 1, dest.Y, dest.Width - 1, dest.Height - 1); } else if ((state & DrawItemState.Selected) == DrawItemState.Selected) { graphics.FillRectangle(new SolidBrush(sideBarColor), dest.X + 1, dest.Y + 1, dest.Width - 1, dest.Height - 1); graphics.DrawLine(new Pen(selectedBorder), dest.Left + 1, dest.Top, dest.Left + 1, dest.Bottom - 1); graphics.DrawLine(new Pen(selectedBorder), dest.Left + 1 + (dest.Width - 1), dest.Top + 1, dest.Left + 1 + (dest.Width - 1), dest.Bottom - 1); graphics.DrawLine(new Pen(selectedBorder), dest.Left + 1, dest.Top, dest.Left + 1 + (dest.Width - 1), dest.Top); } else { graphics.FillRectangle(SystemBrushes.Control, dest.X, dest.Y, dest.Width + 1, dest.Height); } StringFormat format = new StringFormat(); format.HotkeyPrefix = HotkeyPrefix.Show; format.SetTabStops(60, new Single[] { 0 }); graphics.DrawString(Text, font, Brushes.Black, dest.Left + 6, dest.Top + 3, format); }
protected internal override void DrawDocumentStripTab( Graphics graphics, Rectangle bounds, Rectangle contentBounds, Image image, string text, Font font, Color backColor, Color foreColor, DrawItemState state, bool drawSeparator) { Color x477e9d1180ece053 = RendererBase.InterpolateColors(backColor, SystemColors.ControlLightLight, 0.78f); bool xb0f87b71823b1d4e = (state & DrawItemState.Checked) == DrawItemState.Checked; if ((state & DrawItemState.Selected) != DrawItemState.Selected) { xa811784015ed8842.xf8aac789a7846004(graphics, bounds, contentBounds, image, this.ImageSize, text, font, x477e9d1180ece053, backColor, SystemBrushes.ControlText, this.xcee7f670c3cc8729, this.x0b2889b8ff5ec580, this.x0e8b6412ec502dbf, false, this.DocumentTabSize, this.DocumentTabExtra, this.TextFormat, xb0f87b71823b1d4e); } else { xa811784015ed8842.xf8aac789a7846004(graphics, bounds, contentBounds, image, this.ImageSize, text, font, x477e9d1180ece053, backColor, SystemBrushes.ControlText, this.x994b52371e1ca7a9, this.x80caa5727f6ffe52, this.x9196c174a89a4ce4, true, this.DocumentTabSize, this.DocumentTabExtra, this.TextFormat, xb0f87b71823b1d4e); if (false) { ; } } }
public static void OwnerDrawMenuItem(System.Windows.Forms.MenuItem menuItem, DrawItemEventArgs e, string shortcutText) { if (e == null) { throw new ArgumentNullException("e"); } Graphics g = e.Graphics; DrawItemState itemState = e.State; Rectangle BitmapBounds = e.Bounds; BitmapBounds.Width = BitmapWidth + 2; Rectangle ItemBounds = e.Bounds; ItemBounds.X = BitmapWidth; Rectangle ItemTextBounds = e.Bounds; ItemTextBounds.X = (BitmapWidth + HorizontalTextOffset); ItemTextBounds.Y = (e.Bounds.Y + VerticalTextOffset); ItemTextBounds.Width = (e.Bounds.Width); ItemTextBounds.Height = (e.Bounds.Height); DrawBackground(g, itemState, e.Bounds); //DrawBitmap(g, item, itemState); DrawText(g, menuItem, itemState, shortcutText, e.Bounds, ItemTextBounds); }
private ImageList G_ImageList;//声明ImageList字段 private void cbox_DisplayPictures_DrawItem(object sender, DrawItemEventArgs e) { if (G_ImageList != null) //判断ImageList是否为空 { Graphics g = e.Graphics; //得到绘图对象 Rectangle r = e.Bounds; //得到绘图范围 Size imageSize = G_ImageList.ImageSize; //获取图像大小 if (e.Index >= 0) //判断是否有绘制项 { Font fn = new Font("宋体", 10, FontStyle.Bold); //创建字体对象 string s = cbox_DisplayPictures.Items[e.Index].ToString(); //得到绘制项的字符串 DrawItemState dis = e.State; if (e.State == (DrawItemState.NoAccelerator | DrawItemState.NoFocusRect)) { e.Graphics.FillRectangle(new SolidBrush(Color.LightYellow), r); //画条目背景 G_ImageList.Draw(e.Graphics, r.Left, r.Top, e.Index); //绘制图像 e.Graphics.DrawString(s, fn, new SolidBrush(Color.Black), //显示字符串 r.Left + imageSize.Width, r.Top); e.DrawFocusRectangle(); //显示取得焦点时的虚线框 } else { e.Graphics.FillRectangle(new SolidBrush(Color.LightGreen), r); //画条目背景 G_ImageList.Draw(e.Graphics, r.Left, r.Top, e.Index); //绘制图像 e.Graphics.DrawString(s, fn, new SolidBrush(Color.Black), //显示字符串 r.Left + imageSize.Width, r.Top); e.DrawFocusRectangle(); //显示取得焦点时的虚线框 } } } }
/// <summary> /// Initializes a new instance of the <see cref='System.Windows.Forms.StatusBarDrawItemEventArgs'/> /// class using the Forecolor and Backcolor. /// </summary> public StatusBarDrawItemEventArgs(Graphics g, Font font, Rectangle r, int itemId, DrawItemState itemState, StatusBarPanel panel, Color foreColor, Color backColor) : base(g, font, r, itemId, itemState, foreColor, backColor) { Panel = panel; }
// Constructors. public StatusBarDrawItemEventArgs (Graphics graphics, Font font, Rectangle rect, int index, DrawItemState state, StatusBarPanel panel) : base(graphics, font, rect, index, state) { this.panel = panel; }
/// <summary> /// </summary> public static NuGenControlState ToControlState(DrawItemState itemState) { if ( (itemState & DrawItemState.Disabled) > 0 || (itemState & DrawItemState.Grayed) > 0 ) { return NuGenControlState.Disabled; } else if ( (itemState & DrawItemState.HotLight) > 0 || (itemState & DrawItemState.Inactive) > 0 ) { return NuGenControlState.Hot; } else if ( (itemState & DrawItemState.Selected) > 0 ) { return NuGenControlState.Pressed; } else { return NuGenControlState.Normal; } }
public DrawItemEventArgs (Graphics graphics, Font font, Rectangle rect, int index, DrawItemState state) : this (graphics, font, rect, index, state, Control.DefaultForeColor, Control.DefaultBackColor) { }
/// <summary> /// Draws a list item. /// </summary> /// <param name="graphics">The Graphics object to draw on.</param> /// <param name="bounds">The bounds that represents the dimensions of the item rectangle.</param> /// <param name="state">Specifies the state of an item that is being drawn.</param> /// <param name="text">The Text of the item.</param> /// <param name="imageList">Specifies the ImageList of an item.</param> /// <param name="imageIndex">Specifies the ImageIndex of an item.</param> /// <param name="font">The Font to draw the item. </param> /// <param name="foreColor">The Color to draw the string with.</param> /// <param name="textStartPos">The Position for draws of the text.</param> /// <param name="rightToLeft">Specifies that text is right to left.</param> public static void DrawItem(Graphics graphics, Rectangle bounds, DrawItemState state, string text, ImageList imageList, int imageIndex, Font font, Color backColor, Color foreColor, int textStartPos, RightToLeft rightToLeft) { DrawItem(graphics, bounds, state, text, imageList, imageIndex, font, backColor, foreColor, textStartPos, rightToLeft, StringAlignment.Near); }
protected override void OnDrawItem(DrawItemEventArgs e) { DrawItemEventHandler handler = GetDrawItemHandler(); if (handler == null) { Graphics g = e.Graphics; Rectangle itemRect = e.Bounds; if ((e.State & DrawItemState.Selected) > 0) { itemRect.Width--; } DrawItemState state = e.State; int imageIndex = UseFirstImage ? 0 : e.Index; string text = Text; if (e.Index != -1) { text = this.GetItemText(Items[e.Index]); } StiControlPaint.DrawItem(g, itemRect, state, text, ImageList, imageIndex, Font, BackColor, ForeColor, RightToLeft); } else { handler(this, e); } }
/// <summary> /// Paints the control (using the Buffered Paint API). /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void _bufferedPainter_PaintVisualState(object sender, BufferedPaintEventArgs <ComboBoxState> e) { VisualStyleRenderer r = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal); r.DrawParentBackground(e.Graphics, ClientRectangle, this); DrawComboBox(e.Graphics, ClientRectangle, e.State); Rectangle itemBounds = new Rectangle(0, 0, Width - 21, Height); itemBounds.Inflate(-1, -3); itemBounds.Offset(2, 0); // draw the item in the editable portion DrawItemState state = DrawItemState.ComboBoxEdit; if (Focused && ShowFocusCues && !DroppedDown) { state |= DrawItemState.Focus; } if (!Enabled) { state |= DrawItemState.Disabled; } OnDrawItem(new DrawItemEventArgs(e.Graphics, Font, itemBounds, SelectedIndex, state)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Draws a normal menu item including any related icons, checkboxes, /// menu text, shortcuts text, and parent/submenu arrows. /// </summary> /// <param name="bounds">a <c>Rectangle</c> that holds the drawing canvas boundaries /// </param> /// <param name="state">True/False if the menu item is currently selected</param> /// <param name="imageIndex">the image index of the menu icon to draw, defaults to -1 /// </param> /// ------------------------------------------------------------------------------------ void IMenuDrawingHelper.DrawMenu(Rectangle bounds, DrawItemState state, int imageIndex) { Image image = MenuImage(imageIndex); bool selected = (state & DrawItemState.Selected) > 0; if (m_menuItem is LabelMenuItem) { DrawLabelMenuItem(bounds, image); return; } DrawBackground(bounds, state, selected); if (image != null) { DrawImage(bounds, image, selected, m_menuItem.Checked); } else if (m_menuItem.Checked) { DrawCheckmark(bounds, selected); } if (!IsSeperator || m_menuItem is LabelMenuItem) { DrawMenuText(bounds, state); } else { DrawSeparator(bounds); } }
public void DrawTabControlButton( Graphics graphics, Rectangle bounds, SandDockButtonType buttonType, DrawItemState state) { if ((state & DrawItemState.Selected) == DrawItemState.Selected) { bounds.Offset(1, 1); } SandDockButtonType sandDockButtonType = buttonType; if (false) { ; } switch (sandDockButtonType) { case SandDockButtonType.ScrollLeft: x9b2777bb8e78938b.xd70a4c1a2378c84e(graphics, bounds, SystemColors.ControlText, (state & DrawItemState.Disabled) != DrawItemState.Disabled); break; case SandDockButtonType.ScrollRight: x9b2777bb8e78938b.x793dc1a7cf4113f9(graphics, bounds, SystemColors.ControlText, (state & DrawItemState.Disabled) != DrawItemState.Disabled); break; } }
protected override void OnPaint(PaintEventArgs e) { e.Graphics.DrawLine(new Pen(SystemColors.Control, 2), new Point(0, 30), new Point(this.Width, 30)); //e.Graphics.FillRectangle(new SolidBrush(this.BackColor), new Rectangle(0, 0, this.Width, 30)); int xpos = 5; int index = 0; foreach (MyTabPage tabPage in tabPages) { DrawItemState drawState = DrawItemState.Default; Font font = this.Font; if (selectedTabPage == tabPage) { drawState = DrawItemState.Selected; font = new Font(this.Font.FontFamily, this.Font.Size, FontStyle.Bold); } Size textSize = TextRenderer.MeasureText(e.Graphics, tabPage.Text, font, new Size(int.MaxValue, int.MaxValue)); Rectangle rect = new Rectangle(); rect.Location = new Point(xpos, 5); rect.Size = new Size(textSize.Width + 18, 25); DrawItemEventArgs de = new DrawItemEventArgs(e.Graphics, font, rect, index, drawState); DrawItem(de); tabPage.Bounds = rect; xpos += rect.Width + 5; index++; } base.OnPaint(e); }
protected internal abstract void DrawTitleBarButton( Graphics graphics, Rectangle bounds, SandDockButtonType buttonType, DrawItemState state, bool focused, bool toggled);
protected virtual void DrawShape(Graphics g, Rectangle bounds, int index, DrawItemState state) { if (index != -1) { var shape = this.Items[index] as Xwt.Drawing.Image; if (shape != null) { var color = state.HasFlag(DrawItemState.Selected) ? SystemColors.Highlight : BackColor; using (var b = new SolidBrush(color)) { g.FillRectangle(b, bounds); } if (state.HasFlag(DrawItemState.ComboBoxEdit)) { bounds.Inflate(-5, -3); } else { bounds.Inflate(-5, -3); } g.SmoothingMode = SmoothingMode.AntiAlias; var location = bounds.Location.ToXwt(); var size = bounds.Size.ToXwt(); var surface = new GdiSurface() { Graphics = g }; surface.Context.SetColor(color.ToXwt()); surface.Context.DrawImage(shape, location, 1); } } }
void DrawBackground(int index, Graphics g, Rectangle listbounds, DrawItemState state, bool isWithDraw) { if (!isWithDraw) { return; } if ((state & DrawItemState.Selected) > 0) {//選択色 Brush brush = new SolidBrush(OptionForm.Color_List_SelectedColor()); g.FillRectangle(brush, listbounds); brush.Dispose(); return; } if (index != this.LastHoverIndex) {//通常 Brush brush = new SolidBrush(OptionForm.Color_Input_BackColor()); g.FillRectangle(brush, listbounds); brush.Dispose(); } else {//hover Brush brush = new SolidBrush(OptionForm.Color_List_HoverColor()); g.FillRectangle(brush, listbounds); brush.Dispose(); } }
protected internal override void DrawCollapsedTab( Graphics graphics, Rectangle bounds, DockSide dockSide, Image image, string text, Font font, Color backColor, Color foreColor, DrawItemState state, bool vertical) { if (dockSide == DockSide.Left || dockSide == DockSide.Right) { using (Image xe058541ca798c059 = (Image) new Bitmap(image)) { xe058541ca798c059.RotateFlip(RotateFlipType.Rotate90FlipNone); xa811784015ed8842.x36c79cea8e98cf3c(graphics, bounds, dockSide, xe058541ca798c059, text, font, SystemBrushes.ControlDarkDark, SystemColors.ControlDark, this.TabTextDisplay == TabTextDisplayMode.AllTabs); } } else { xa811784015ed8842.x36c79cea8e98cf3c(graphics, bounds, dockSide, image, text, font, SystemBrushes.ControlDarkDark, SystemColors.ControlDark, this.TabTextDisplay == TabTextDisplayMode.AllTabs); } }
public StatusBarDrawItemEventArgs (Graphics g, Font font, Rectangle r, int itemId, DrawItemState itemState, StatusBarPanel panel, Color foreColor, Color backColor) : base (g, font, r, itemId, itemState) { this.panel = panel; }
public void DrawItem(DrawItemEventArgs e, int type) { Graphics g = e.Graphics; Rectangle bounds = e.Bounds; DrawItemState state = e.State; if ((state & DrawItemState.Selected) != 0) { g.FillRectangle(Brushes.LightGreen, bounds); } else { g.FillRectangle(SystemBrushes.Window, bounds); } if (type == 0) { int startX = 40 + Padding - TitleLevel * 20; g.DrawString(Title, GetTitleFont(type), Brushes.Black, startX, bounds.Top + Padding); g.DrawString(Subtitle, TextFont, Brushes.Black, new Rectangle(startX, bounds.Top + Padding + TitleHeight + Spacing, bounds.Width - startX - 2 * Padding, bounds.Height)); } else if (type == 1) { int startX = Padding; g.DrawString(Title, GetTitleFont(type), Brushes.Black, startX, bounds.Top + Padding); g.DrawString(Subtitle, TextFont, Brushes.Black, new Rectangle(startX, bounds.Top + Padding + TitleHeight + Spacing, bounds.Width - startX - 2 * Padding, bounds.Height)); } }
/// <summary> /// Occurs when an element within the <see cref="ImageComboBox"/> is drawn. /// </summary> /// <param name="e">The <see cref="DrawItemEventArgs"/> /// which determines which element is being drawn.</param> protected override void OnDrawItem(DrawItemEventArgs e) { var index = e.Index; if (index != -1) { object item = base.Items[index]; if (item is ImageObjectItem) { ImageObjectItem imageItem = (ImageObjectItem)item; DrawItemState newState = e.State; if (!imageItem.Enabled) { newState |= DrawItemState.Disabled; } if (newState != e.State) { e = new DrawItemEventArgs(e.Graphics, e.Font, e.Bounds, e.Index, newState); } if (this.Style != null) { this.Style.OnDrawItemEvent(imageItem, e, this.Font); } } } base.OnDrawItem(e); }
protected override void WndProc(ref System.Windows.Forms.Message m) { base.WndProc(ref m); switch (m.Msg) { case (int)ReflectedMessages.OCM_DRAWITEM: { DrawItemStruct dis = (DrawItemStruct)m.GetLParam(typeof(DrawItemStruct)); Graphics graph = Graphics.FromHdc(dis.hDC); Rectangle rect = new Rectangle(dis.rcItem.left, dis.rcItem.top, dis.rcItem.right - dis.rcItem.left, dis.rcItem.bottom - dis.rcItem.top); int index = dis.itemID; DrawItemState state = DrawItemState.None; System.Windows.Forms.DrawItemEventArgs e = new System.Windows.Forms.DrawItemEventArgs(graph, Font, rect, index, state, ForeColor, BackColor); if (this.DrawItem != null) { this.DrawItem(this, e); } OnDrawItem(e); graph.Dispose(); break; } case 8236: WmReflectMeasureItem(ref m); break; } }
/// <summary> /// Occurs when an element needs redrawn. /// </summary> /// <param name="index">The <see cref="Int32"/> value representing /// the ordinal index of the element to redraw.</param> private void RedrawItem(int index) { if ((index == -1) || (index >= this.items.Count)) { return; } ImageObjectItem item = this.items[index]; DrawItemState diState = DrawItemState.Default; Rectangle itemRect = this.GetItemRectangle(index); foreach (int idx in this.SelectedIndices) { if (idx == index) { diState |= DrawItemState.Selected; } } if (this.Focused) { diState |= DrawItemState.Focus; } DrawItemEventArgs dieas = new DrawItemEventArgs(this.CreateGraphics(), this.Font, itemRect, index, diState, this.ForeColor, this.BackColor); this.OnDrawItem(dieas); dieas.Graphics.Dispose(); }
/// <summary> /// </summary> public static NuGenControlState ToControlState(DrawItemState itemState) { if ( (itemState & DrawItemState.Disabled) > 0 || (itemState & DrawItemState.Grayed) > 0 ) { return(NuGenControlState.Disabled); } else if ( (itemState & DrawItemState.HotLight) > 0 || (itemState & DrawItemState.Inactive) > 0 ) { return(NuGenControlState.Hot); } else if ( (itemState & DrawItemState.Selected) > 0 ) { return(NuGenControlState.Pressed); } else { return(NuGenControlState.Normal); } }
/// <summary> /// Occurs when an element within the <see cref="ImageListBox"/> is drawn. /// </summary> /// <param name="e">The <see cref="DrawItemEventArgs"/> /// which determines which element is being drawn.</param> protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e) { if ((e.Index != -1) && e.Index < base.Items.Count) { object item = base.Items[e.Index]; if (item is ImageObjectItem) { ImageObjectItem imageItem = (ImageObjectItem)item; DrawItemState k = e.State; if (!imageItem.Enabled) { k |= DrawItemState.Disabled; } if (!this.Enabled) { k |= DrawItemState.ComboBoxEdit; } if (k != e.State) { e = new DrawItemEventArgs(e.Graphics, e.Font, e.Bounds, e.Index, k); } if (this.Style != null) { this.Style.OnDrawItemEvent(imageItem, e, this.Font); } } } base.OnDrawItem(e); }
protected internal override void DrawDocumentStripTab( Graphics graphics, Rectangle bounds, Rectangle contentBounds, Image image, string text, Font font, Color backColor, Color foreColor, DrawItemState state, bool drawSeparator) { bool xb0f87b71823b1d4e = (state & DrawItemState.Checked) == DrawItemState.Checked; while ((uint)drawSeparator >= 0U && (state & DrawItemState.Selected) != DrawItemState.Selected) { xa811784015ed8842.xf8aac789a7846004(graphics, bounds, contentBounds, image, this.ImageSize, text, font, SystemInformation.HighContrast ? SystemColors.Control : SystemColors.ControlLightLight, SystemInformation.HighContrast ? SystemColors.Control : backColor, SystemBrushes.ControlText, this.InactiveDocumentBorderColor, this.x0b2889b8ff5ec580, this.x0e8b6412ec502dbf, false, this.DocumentTabSize, this.DocumentTabExtra, this.TextFormat, xb0f87b71823b1d4e); if ((uint)xb0f87b71823b1d4e - (uint)xb0f87b71823b1d4e <= uint.MaxValue) { return; } } xa811784015ed8842.xf8aac789a7846004(graphics, bounds, contentBounds, image, this.ImageSize, text, font, SystemInformation.HighContrast ? SystemColors.Control : SystemColors.ControlLightLight, SystemInformation.HighContrast ? SystemColors.Control : SystemColors.ControlLightLight, SystemBrushes.ControlText, this.ActiveDocumentBorderColor, this.x80caa5727f6ffe52, this.x9196c174a89a4ce4, true, this.DocumentTabSize, this.DocumentTabExtra, this.TextFormat, xb0f87b71823b1d4e); if (false) { ; } }
protected internal override System.Drawing.Size MeasureDocumentStripTab( Graphics graphics, Image image, string text, Font font, DrawItemState state) { TextFormatFlags textFormat = this.TextFormat; int num1; if ((num1 & 0) == 0) { goto label_9; } label_3: int width; using (Font font1 = new Font(font, FontStyle.Bold)) width = TextRenderer.MeasureText((IDeviceContext)graphics, text, font1, new System.Drawing.Size(int.MaxValue, int.MaxValue), textFormat).Width; int num2 = width + 14; if (image != null) { num2 += 20; } return(new System.Drawing.Size(num2 + this.DocumentTabExtra, 0)); label_9: textFormat &= ~TextFormatFlags.NoPrefix; goto label_3; }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// <param name="bounds"></param> /// <param name="state"></param> /// <param name="selected"></param> /// ------------------------------------------------------------------------------------ private void DrawBackground(Rectangle bounds, DrawItemState state, bool selected) { if ((!selected && (state & DrawItemState.HotLight) == 0)) { DrawBgUnselectedNotHot(bounds); } else { if (IsTopLevel && selected) { DrawBgSelectedTopLevel(bounds); } else { if (m_menuItem.Enabled) { DrawBgHotOrSelectedEnabled(bounds); } else { DrawBgHotOrSelectedDisabled(bounds); } } } }
public StatusBarDrawItemEventArgs (Graphics g, Font font, Rectangle r, int itemId, DrawItemState itemState, StatusBarPanel panel) : this (g, font, r, itemId, itemState, panel, Control.DefaultForeColor, Control.DefaultBackColor) { }
/// <summary> /// Draws a list item. /// </summary> /// <param name="graphics">The Graphics object to draw on.</param> /// <param name="bounds">The bounds that represents the dimensions of the item rectangle.</param> /// <param name="state">Specifies the state of an item that is being drawn.</param> public static void DrawItem(Graphics graphics, Rectangle bounds, DrawItemState state, Color backColor, Color foreColor) { if ((state & DrawItemState.Focus) != 0) { graphics.FillRectangle(StiBrushes.Focus, bounds.X, bounds.Y, bounds.Width + 1, bounds.Height); graphics.DrawRectangle(StiPens.SelectedText, bounds.X, bounds.Y, bounds.Width, bounds.Height - 1); } else if ((state & DrawItemState.Selected) != 0) { graphics.FillRectangle(StiBrushes.Selected, bounds.X, bounds.Y, bounds.Width + 1, bounds.Height); graphics.DrawRectangle(StiPens.SelectedText, bounds.X, bounds.Y, bounds.Width, bounds.Height - 1); } else { using (SolidBrush brush = new SolidBrush(backColor)) { graphics.FillRectangle(brush, bounds.X, bounds.Y, bounds.Width + 1, bounds.Height); } } }
protected internal override void DrawDocumentStripButton(Graphics graphics, Rectangle bounds, SandDockButtonType buttonType, DrawItemState state) { vmethod_0(graphics, bounds, state); if ((state & DrawItemState.Selected) == DrawItemState.Selected) { bounds.Offset(1, 1); } switch (buttonType) { case SandDockButtonType.Close: using (var pen = new Pen(color_6)) { ButtonRenderHelper.DrawDocumentStripCloseButton(graphics, bounds, pen); return; } case SandDockButtonType.Pin: case SandDockButtonType.WindowPosition: return; case SandDockButtonType.ScrollLeft: break; case SandDockButtonType.ScrollRight: ButtonRenderHelper.DrawScrollRightDockButton(graphics, bounds, color_6, (state & DrawItemState.Disabled) != DrawItemState.Disabled); return; case SandDockButtonType.ActiveFiles: ButtonRenderHelper.DrawPositionDockButton(graphics, bounds, SystemPens.ControlText); return; default: return; } ButtonRenderHelper.DrawScrollLeftDockButton(graphics, bounds, color_6, (state & DrawItemState.Disabled) != DrawItemState.Disabled); }
/// <summary>Overrides the OnDrawItem for the CheckedListBox so that we can customize how the items are drawn.</summary> /// <param name="e">The System.Windows.Forms.DrawItemEventArgs object with the details</param> /// <remarks>A CheckedListBox can only have one item selected at a time and it's always the item in focus. /// So, don't draw an item as selected since the selection colors are hideous. /// Just use the focus rect to indicate the selected item.</remarks> protected override void OnDrawItem(DrawItemEventArgs e) { Color foreColor = this.ForeColor; Color backColor = this.BackColor; DrawItemState s2 = e.State; //If the item is in focus, then it should always have the focus rect. //Sometimes it comes in with Focus and NoFocusRect. //This is annoying and the user can't tell where their focus is, so give it the rect. if ((s2 & DrawItemState.Focus) == DrawItemState.Focus) { if (DrawFocusRect) { s2 &= ~DrawItemState.NoFocusRect; } else { s2 &= DrawItemState.NoFocusRect; } } //Turn off the selected state. Note that the color has to be overridden as well, but I just did that for all drawing since I want them to match. if ((s2 & DrawItemState.Selected) == DrawItemState.Selected) { s2 &= ~DrawItemState.Selected; } //Console.WriteLine("Draw " + e.Bounds + e.State + " --> " + s2); //Compile the new drawing args and let the base draw the item. DrawItemEventArgs e2 = new DrawItemEventArgs(e.Graphics, e.Font, e.Bounds, e.Index, s2, foreColor, backColor); base.OnDrawItem(e2); }
public StatusBarDrawItemEventArgs(Graphics g, Font font, Rectangle_ r, int itemId, DrawItemState itemState, StatusBarPanel panel) : this(g, font, r, itemId, itemState, panel, Control.DefaultForeColor, Control.DefaultBackColor) { }
/// //////////////////////////////////////////////////////////////////// /// <summary> /// Override the CheckedListBox method to allow changes to the /// foreground, background, and font. /// </summary> /// <param name="e"></param> protected override void OnDrawItem(DrawItemEventArgs e) { Color foreColor = (GetForeColor != null) ? GetForeColor(this, e) : e.ForeColor; Color backColor = (GetBackColor != null) ? GetBackColor(this, e) : e.BackColor; // // The CheckListBox is going to ignore the font in the event // args and use its own. So, make its own the one we want it // to be. For this to always work right, we will have to shut // down the OnFontChanged method below. // if (GetFont != null) { this.Font = GetFont(this, e); } // // If desired, draw an item focused, but not selected. // DrawItemState state = (DrawFocusedIndicator) ? ((e.State & DrawItemState.Focus) == DrawItemState.Focus) ? DrawItemState.Focus : DrawItemState.None : e.State; // // e.Font is going to be ignored. // DrawItemEventArgs e2 = new DrawItemEventArgs(e.Graphics, e.Font, e.Bounds, e.Index, state, foreColor, backColor); base.OnDrawItem(e2); }
private void _DrawFooterPaneBackground(Graphics gfx, Rectangle bounds, DrawItemState itemState) { Color beginColor; Color endColor; if (((itemState & DrawItemState.Selected) == DrawItemState.Selected) || ((itemState & (DrawItemState.HotLight | DrawItemState.Checked)) == (DrawItemState.HotLight | DrawItemState.Checked))) { beginColor = this.PaneSelectedBackgroundColor1; endColor = this.PaneSelectedBackgroundColor2; } else if ((itemState & DrawItemState.HotLight) == DrawItemState.HotLight) { beginColor = this._ProfessionalColorTable.ButtonPressedGradientBegin; endColor = this._ProfessionalColorTable.ButtonPressedGradientEnd; } else if ((itemState & DrawItemState.Checked) == DrawItemState.Checked) { beginColor = this.PaneCheckedBackgroundColor1; endColor = this.PaneCheckedBackgroundColor2; } else { beginColor = this.PaneBackgroundColor1; endColor = this.PaneBackgroundColor2; } using (LinearGradientBrush fillBrush = new LinearGradientBrush( new Point(bounds.X, bounds.Y - 1), new Point(bounds.X, bounds.Bottom), beginColor, endColor)) { gfx.FillRectangle(fillBrush, bounds); } }
public StatusBarDrawItemEventArgs (Graphics graphics, Font font, Rectangle rect, int index, DrawItemState state, StatusBarPanel panel, Color foreColor, Color backColor) : base(graphics, font, rect, index, state, foreColor, backColor) { this.panel = panel; }
public DrawItemEventArgs(System.Drawing.Graphics graphics, System.Drawing.Font font, Rectangle rect, int index, DrawItemState state, Color foreColor, Color backColor) { this.graphics = graphics; this.font = font; this.rect = rect; this.index = index; this.state = state; this.foreColor = foreColor; this.backColor = backColor; }
/// <include file='doc\DrawItemEvent.uex' path='docs/doc[@for="DrawItemEventArgs.DrawItemEventArgs"]/*' /> /// <devdoc> /// Creates a new DrawItemEventArgs with the given parameters. /// </devdoc> public DrawItemEventArgs(Graphics graphics, Font font, Rectangle rect, int index, DrawItemState state) { this.graphics = graphics; this.font = font; this.rect = rect; this.index = index; this.state = state; this.foreColor = SystemColors.WindowText; this.backColor = SystemColors.Window; }
/// <summary> /// Initializes a new instance /// </summary> public DrawItemEventArgs(System.Drawing.Graphics graphics, System.Drawing.Font font , System.Drawing.Rectangle rect , System.Int32 index , DrawItemState state ) { this.graphics = graphics; this.font = font; this.rect = rect; this.index = index; this.state = state; this.foreColor = SystemColors.ControlText; this.backColor = SystemColors.Window; }
public void DrawTabControlButton(Graphics graphics, Rectangle bounds, SandDockButtonType buttonType, DrawItemState state) { if ((state & DrawItemState.Selected) == DrawItemState.Selected) bounds.Offset(1, 1); switch (buttonType) { case SandDockButtonType.ScrollLeft: ButtonRenderHelper.DrawScrollLeftDockButton(graphics, bounds, SystemColors.ControlText, (state & DrawItemState.Disabled) != DrawItemState.Disabled); return; case SandDockButtonType.ScrollRight: ButtonRenderHelper.DrawScrollRightDockButton(graphics, bounds, SystemColors.ControlText, (state & DrawItemState.Disabled) != DrawItemState.Disabled); return; default: return; } }
protected internal override void DrawCollapsedTab(Graphics graphics, Rectangle bounds, DockSide dockSide, Image image, string text, Font font, Color backColor, Color foreColor, DrawItemState state, bool vertical) { using (Brush brush = CreateLinearGradientBrush(bounds, vertical ? CollapsedTabVerticalBackground : CollapsedTabHorizontalBackground, vertical ? LinearGradientMode.Horizontal : LinearGradientMode.Vertical)) { if (dockSide != DockSide.Left && dockSide != DockSide.Right) { RenderHelper.smethod_6(graphics, bounds, dockSide, image, text, font, brush, Brushes.Black, CollapsedTabBorder, TabTextDisplay == TabTextDisplayMode.AllTabs); return; } using (var bm = new Bitmap(image)) { bm.RotateFlip(RotateFlipType.Rotate90FlipNone); RenderHelper.smethod_6(graphics, bounds, dockSide, bm, text, font, brush, Brushes.Black, CollapsedTabBorder, TabTextDisplay == TabTextDisplayMode.AllTabs); } } }
protected internal override void DrawCollapsedTab(Graphics graphics, Rectangle bounds, DockSide dockSide, Image image, string text, Font font, Color backColor, Color foreColor, DrawItemState state, bool vertical) { using (var brush = new SolidBrush(backColor)) graphics.FillRectangle(brush, bounds); if (dockSide != DockSide.Top) { graphics.DrawLine(pen_2, bounds.Left, bounds.Top, bounds.Right, bounds.Top); } if (dockSide != DockSide.Right) { graphics.DrawLine(pen_2, bounds.Right, bounds.Top, bounds.Right, bounds.Bottom); } if (dockSide != DockSide.Bottom) { graphics.DrawLine(pen_2, bounds.Left, bounds.Bottom, bounds.Right, bounds.Bottom); } if (dockSide != DockSide.Left) { graphics.DrawLine(pen_2, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom); } bounds.Inflate(-2, -2); if (vertical) bounds.Offset(0, 1); else bounds.Offset(1, 0); graphics.DrawImage(image, new Rectangle(bounds.Left, bounds.Top, image.Width, image.Height)); if (text.Length == 0) return; if (vertical) { bounds.Offset(0, 23); graphics.DrawString(text, font, solidBrush_1, bounds, VerticalTextFormat); return; } bounds.Offset(23, 0); graphics.DrawString(text, font, solidBrush_1, bounds, HorizontalTextFormat); }
public Size MeasureTabControlTab(Graphics graphics, Image image, string text, Font font, DrawItemState state) { int w; using (new Font(font, FontStyle.Bold)) w = TextRenderer.MeasureText(graphics, text, font, new Size(2147483647, 2147483647), _textFormat).Width; w += 24; if (image != null) w += image.Width + 4; w += TabControlTabExtra; return new Size(w, 0); }
public void DrawTabControlTab(Graphics graphics, Rectangle bounds, Image image, string text, Font font, Color backColor, Color foreColor, DrawItemState state, bool drawSeparator) { int arg_07_0 = bounds.Height; var flag = (state & DrawItemState.Selected) == DrawItemState.Selected; Color color = flag ? color_4 : color_6; Color color2 = flag ? color_5 : color_7; if (TabColorBlend > 0.0) { color = RendererBase.InterpolateColors(color, backColor, (float)TabColorBlend); color2 = RendererBase.InterpolateColors(color2, backColor, (float)TabColorBlend); } using (var brush = new LinearGradientBrush(bounds, color, color2, LinearGradientMode.Vertical)) { graphics.FillPolygon(brush, method_0(bounds, false)); } var smoothingMode = graphics.SmoothingMode; graphics.SmoothingMode = SmoothingMode.AntiAlias; using (Pen pen = new Pen(flag ? color_0 : color_2)) graphics.DrawLines(pen, method_0(bounds, false)); using (Pen pen2 = new Pen(flag ? color_1 : color_3)) { graphics.DrawLines(pen2, method_0(bounds, true)); if (!flag) { Color color3 = RendererBase.InterpolateColors(color_3, color_2, 0.5f); using (Pen pen3 = new Pen(color3)) { graphics.DrawLines(pen3, new[] { new Point(bounds.Right - 4, bounds.Y + 1), new Point(bounds.Right - 2, bounds.Y + 3), new Point(bounds.Right - 2, bounds.Bottom - 2) }); } } } if (flag) { using (Pen pen4 = new Pen(color2)) { graphics.DrawLine(pen4, bounds.X + 1, bounds.Bottom - 1, bounds.Right - 1, bounds.Bottom - 1); } } graphics.SmoothingMode = smoothingMode; if ((state & DrawItemState.Checked) == DrawItemState.Checked) { var rectangle = bounds; rectangle.X += TabControlTabExtra; rectangle.Width -= TabControlTabExtra; rectangle.Inflate(-4, -3); rectangle.X++; rectangle.Height++; ControlPaint.DrawFocusRectangle(graphics, rectangle); } bounds.X += TabControlTabExtra + 6; bounds.Width -= TabControlTabExtra + 6; bounds.Inflate(-2, 0); if (image != null) { Rectangle destRect = new Rectangle(bounds.X, bounds.Y + bounds.Height / 2 - image.Height / 2, image.Width, image.Height); graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel); bounds.X += image.Width + 4; bounds.Width -= image.Width + 4; } if (bounds.Width > 4) { if (flag) { using (Font font2 = new Font(font, FontStyle.Bold)) { TextRenderer.DrawText(graphics, text, font2, bounds, foreColor, _textFormat); return; } } TextRenderer.DrawText(graphics, text, font, bounds, foreColor, _textFormat); } }
private void DrawTextSelected(Graphics g, SmartListItem item, string text, Brush textBrush, int selStart, int selLen, Rectangle rc, DrawItemState state) { SizeF textSize = g.MeasureString(text, item.Font); SizeF sizeStart = SizeF.Empty; Brush backBrush = null; Brush selBrush = null; string selStr = text.Substring(0, selLen); string rightStr = text.Substring(selLen, text.Length - selLen); //if (selStart > 0) sizeStart = g.MeasureString(selStr, item.Font); Rectangle rcSel = new Rectangle(rc.X, rc.Y + 1, (int)sizeStart.Width, rc.Height); Rectangle rcRight = new Rectangle((int)(rc.X+sizeStart.Width), rc.Y + 1, (int)(textSize.Width - sizeStart.Width), rc.Height); if (state == DrawItemState.Selected) { backBrush = new SolidBrush(SystemColors.HighlightText); selBrush = new SolidBrush(SystemColors.Highlight); } else { backBrush = new SolidBrush(SystemColors.Highlight); selBrush = new SolidBrush(SystemColors.HighlightText); } g.FillRectangle(backBrush, rcSel); g.DrawString(selStr, item.Font, selBrush, rcSel); g.DrawString(rightStr, item.Font, textBrush, rcRight); backBrush.Dispose(); selBrush.Dispose(); }
bool IsSelected(DrawItemState state) { return (state & DrawItemState.Selected) == DrawItemState.Selected; }
private NuGenControlState GetControlState(DrawItemState itemState) { return NuGenDrawItemStateTranslator.ToControlState(itemState); }
/// <include file='doc\StatusBarDrawItemEvent.uex' path='docs/doc[@for="StatusBarDrawItemEventArgs.StatusBarDrawItemEventArgs"]/*' /> /// <devdoc> /// <para> /// Initializes a new instance of the <see cref='System.Windows.Forms.StatusBarDrawItemEventArgs'/> /// class. /// </para> /// </devdoc> public StatusBarDrawItemEventArgs(System.Drawing.Graphics g, Font font, Rectangle r, int itemId, DrawItemState itemState, StatusBarPanel panel) : base(g, font, r, itemId, itemState) { this.panel = panel; }
public void DrawBackground(Graphics g, Rectangle bounds, DrawItemState state, bool toplevel, bool hasicon, bool enabled) { bool selected = (state & DrawItemState.Selected) > 0; if (selected || ((state & DrawItemState.HotLight) > 0)) { if (toplevel && selected) { // draw toplevel, selected menuitem bounds.Inflate(-1, 0); g.FillRectangle(new SolidBrush(stripeColor), bounds); if (ColorUtil.UsingCustomColor) { GDIUtil.Draw3DRect(g, bounds, ColorUtil.VSNetBorderColor, ColorUtil.VSNetControlColor); } else { ControlPaint.DrawBorder3D(g, bounds.Left, bounds.Top, bounds.Width, bounds.Height, Border3DStyle.Flat, Border3DSide.Top | Border3DSide.Left | Border3DSide.Right); } } else { // draw menuitem hotlighted if (enabled) { g.FillRectangle(new SolidBrush(selectionColor), bounds); g.DrawRectangle(new Pen(borderColor), bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1); } else { // Check if menu item was selected by using the mouse or the keyboard RECT rc = new RECT(); IntPtr parentHandle = Parent.Handle; uint index = (uint)Index; WindowsAPI.GetMenuItemRect(IntPtr.Zero, parentHandle, index, ref rc); Rectangle menuRect = new Rectangle(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); Point mp = Control.MousePosition; if (!menuRect.Contains(mp)) { // Menu was selected by using keyboard g.FillRectangle(new SolidBrush(bgColor), bounds); g.DrawRectangle(new Pen(borderColor), bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1); } else { // Menu was selected by using mouse g.FillRectangle(new SolidBrush(stripeColor), bounds); bounds.X += STRIPE_WIDTH; bounds.Width -= STRIPE_WIDTH; g.FillRectangle(new SolidBrush(bgColor), bounds); } } } } else { if (!toplevel) { // draw menuitem, unselected g.FillRectangle(new SolidBrush(stripeColor), bounds); bounds.X += STRIPE_WIDTH; bounds.Width -= STRIPE_WIDTH; g.FillRectangle(new SolidBrush(bgColor), bounds); } else { // draw toplevel, unselected menuitem g.FillRectangle(SystemBrushes.Control, bounds); } } }
public void DrawMenuText(Graphics g, Rectangle bounds, string text, string shortcut, bool enabled, bool toplevel, DrawItemState state) { using (StringFormat stringformat = new StringFormat()) { stringformat.HotkeyPrefix = HotkeyPrefix.Show; // if 3D background happens to be black, as it is the case when // using a high contrast color theme, then make sure text is white bool highContrast = false; bool whiteHighContrast = false; if (SystemColors.Control.ToArgb() == Color.FromArgb(255, 0, 0, 0).ToArgb()) highContrast = true; if (SystemColors.Control.ToArgb() == Color.FromArgb(255, 255, 255, 255).ToArgb()) whiteHighContrast = true; // if menu is a top level, extract the ampersand that indicates the shortcut character // so that the menu text is centered string textTopMenu = text; if (toplevel) { int index = text.IndexOf("&"); if (index != -1) { // remove it text = text.Remove(index, 1); } } int textwidth = (int)(g.MeasureString(text, SystemInformation.MenuFont).Width); int x = toplevel ? bounds.Left + (bounds.Width - textwidth) / 2 : bounds.Left + iconSize + 10; int topGap = 4; if (toplevel) topGap = 2; int y = bounds.Top + topGap; Brush brush = null; try { if (!enabled) brush = new SolidBrush(Color.FromArgb(120, SystemColors.MenuText)); else if (highContrast) brush = new SolidBrush(Color.FromArgb(255, SystemColors.MenuText)); else brush = new SolidBrush(Color.Black); if (whiteHighContrast && ((state & DrawItemState.HotLight) > 0 || ((state & DrawItemState.Selected) > 0 && !toplevel))) { brush.Dispose(); brush = new SolidBrush(Color.FromArgb(255, Color.White)); } if (toplevel) text = textTopMenu; g.DrawString(text, SystemInformation.MenuFont, brush, x, y, stringformat); // don't draw the shortcut for top level menus // in case there was actually one if (!toplevel) { // draw shortcut right aligned stringformat.FormatFlags |= StringFormatFlags.DirectionRightToLeft; g.DrawString(shortcut, SystemInformation.MenuFont, brush, bounds.Width - 10, bounds.Top + topGap, stringformat); } } finally { brush.Dispose(); } } }
/// <summary> /// Menu bitmap method. Returns the bitmap to draw for the owner draw menu item. Override /// this method in a derived class to return the appropriate bitmap to draw based on the /// draw item state of the MenuItem. /// </summary> /// <param name="drawItemState">The draw item state.</param> /// <returns>Bitmap to draw.</returns> protected virtual Bitmap MenuBitmap(DrawItemState drawItemState) { return null; }
/// <summary> /// Draws a menu item. /// </summary> /// <param name="drawItemState">A DrawItemEventArgs that contains the event data.</param> /// <param name="rect">A DrawItemEventArgs that contains the client rectangle.</param> private void DrawMenuItem(DrawItemState drawItemState, Rectangle rect) { // Create graphics context on the offscreen bitmap and set the bounds for painting. Graphics graphics = Graphics.FromImage(offscreenBitmap); graphics.CompositingMode = CompositingMode.SourceOver; graphics.CompositingQuality = CompositingQuality.HighQuality; BidiGraphics g = new BidiGraphics(graphics, new Rectangle(Point.Empty, offscreenBitmap.Size)); try { Rectangle bounds = new Rectangle(0, 0, offscreenBitmap.Width, offscreenBitmap.Height); // Fill the menu item with the system-defined menu color. g.FillRectangle(SystemBrushes.Menu, bounds); // Fill the bitmap area with the system-defind control color. Rectangle bitmapAreaRectangle = new Rectangle(bounds.X, bounds.Y, STANDARD_BITMAP_AREA_WIDTH, bounds.Height); // Fill the background. /* using (SolidBrush solidBrush = new SolidBrush(ApplicationManager.ApplicationStyle.MenuBitmapAreaColor)) graphics.FillRectangle(solidBrush, bitmapAreaRectangle); */ Color backgroundColor = SystemColors.Menu; // If the item is selected, draw the selection rectangle. if ((drawItemState & DrawItemState.Selected) != 0) { DrawHotlight(g, SystemColors.Highlight, bounds, true); backgroundColor = offscreenBitmap.GetPixel(2, 2); } // Obtain the bitmap to draw. If there is one, draw it centered in the bitmap area. Bitmap bitmap = MenuBitmap(drawItemState); if (bitmap != null) g.DrawImage(false, bitmap, new Point( bounds.X + Utility.CenterMinZero(bitmap.Width, bitmapAreaRectangle.Width), bounds.Y + Utility.CenterMinZero(bitmap.Height, bitmapAreaRectangle.Height))); // Obtain the menu text. If it's not "-", then this is a menu item. Otherwise, it's // a separator menu item. if (MenuText() != "-") { // Calculate the text area rectangle. This area excludes an area at the right // edge of the menu item where the system draws the cascade indicator. It would // have been better if MenuItem let us draw the indicator (we did say "OwnerDraw" // afterall), but this is just how it works. Rectangle textAreaRectangle = new Rectangle(bounds.X + STANDARD_BITMAP_AREA_WIDTH + STANDARD_TEXT_PADDING, bounds.Y, bounds.Width - (STANDARD_BITMAP_AREA_WIDTH + STANDARD_TEXT_PADDING + STANDARD_RIGHT_EDGE_PAD), bounds.Height); // Select the brush to draw the menu text with. Color color; if ((drawItemState & DrawItemState.Disabled) == 0) color = SystemColors.MenuText; else color = SystemColors.GrayText; // Determine the size of the shortcut, if it is being shown. if (!(MenuType == MenuType.Context)) { string shortcut; Size shortcutSize; if (ShowShortcut && Shortcut != Shortcut.None) { shortcut = FormatShortcutString(Shortcut); shortcutSize = MeasureShortcutMenuItemText(graphics, shortcut); } else { shortcut = null; shortcutSize = MeasureShortcutMenuItemText(graphics, FormatShortcutString(Shortcut.CtrlIns)); } // Draw the shortcut. if (shortcut != null) { Rectangle shortcutTextRect = textAreaRectangle; TextFormatFlags textFormatTemp = shortcutStringFormat; //DisplayHelper.FixupGdiPlusLineCentering(graphics, menuFont, shortcut, ref stringFormatTemp, ref shortcutTextRect); // Draw the shortcut text. g.DrawText(shortcut, menuFont, shortcutTextRect, color, backgroundColor, textFormatTemp); } // Reduce the width of the text area rectangle to account for the shortcut and // the padding before it. textAreaRectangle.Width -= shortcutSize.Width + STANDARD_TEXT_PADDING; } // Determine which StringFormat to use when drawing the menu item text. TextFormatFlags textFormat; if ((drawItemState & DrawItemState.NoAccelerator) != 0) textFormat = menuItemTextNoHotKeyStringFormat; else textFormat = menuItemTextHotKeyStringFormat; //DisplayHelper.FixupGdiPlusLineCentering(graphics, menuFont, MenuText(), ref stringFormat, ref textAreaRectangle); // Draw the text. g.DrawText(MenuText(), menuFont, textAreaRectangle, color, backgroundColor, textFormat); } else { // Calculate the separator line rectangle. This area excludes an area at the right // edge of the menu item where the system draws the cascade indicator. It would // have been better if MenuItem let us draw the indicator (we did say "OwnerDraw" // after all), but this is just how it works. Rectangle separatorLineRectangle = new Rectangle(bounds.X + STANDARD_SEPARATOR_PADDING, bounds.Y + Utility.CenterMinZero(1, bounds.Height), bounds.Width - STANDARD_SEPARATOR_PADDING, 1); // Fill the separator line rectangle. g.FillRectangle(SystemBrushes.ControlDark, separatorLineRectangle); } } finally { // We're finished with the double buffered painting. Dispose of the graphics context // and draw the offscreen image. Cache the offscreen bitmap, though. graphics.Dispose(); } }
// *********************************************************************** // HELPER: DrawText // INPUT : Graphics, menu item // NOTES : Paints the text of the menu item private void DrawText(Graphics g, MenuItem item, DrawItemState itemState) { // the foreground brush Brush foreBrush; // Handle the separator as a special case; then return if (item.Text == "-") { DrawSeparator(g); return; } // Determine the foreground brush to use based on the state // NOTE: you could use gradients too if (!item.Enabled) { foreBrush = new SolidBrush(MenuItemForeColorDisabled); } else { foreBrush = new SolidBrush(MenuItemForeColor); } // if ( default item, use bold Font tmpFont; bool defaultItem; defaultItem = ((itemState & DrawItemState.Default) > 0); if ((defaultItem)) { tmpFont = new Font(ItemFont, FontStyle.Bold); } else { tmpFont = ItemFont; } // get { text and keyboard shortcut mySingleton to paint string textToPaint = GetEffectiveText(item); // Text and shortcut are null-separated. Split the string in two parts string[] parts = textToPaint.Split('\0'); // Format the string(s) to render StringFormat strFormat = new StringFormat(); strFormat.HotkeyPrefix = HotkeyPrefix.Show; strFormat.LineAlignment = StringAlignment.Center; // Paint text if (parts.Length == 1) { // Paint when no shortcut mySingleton is found g.DrawString(textToPaint, tmpFont, foreBrush, ItemTextBounds, strFormat); } else { // Paint text when shortcut mySingleton is found g.DrawString(parts[0], tmpFont, foreBrush, ItemTextBounds, strFormat); // Paint right-aligned shortcut mySingleton RectangleF rect = new RectangleF(ItemBounds.X, ItemBounds.Y, ItemBounds.Width, ItemBounds.Height); rect.Width -= BitmapWidth + HorizontalTextOffset + RightOffset; strFormat.FormatFlags = StringFormatFlags.DirectionRightToLeft; g.DrawString(parts[1], tmpFont, foreBrush, rect, strFormat); } // Cleanup resources foreBrush.Dispose(); }
// *********************************************************************** // HELPER: DrawBitmap // INPUT : Graphics, menu item, state of the item // NOTES : Renders the bitmap for the current item taking into account the // current state of the item public virtual void DrawBitmap(Graphics g, MenuItem item, DrawItemState itemState) { // Grab the current state of the menu item //bool isSelected = (itemState & DrawItemState.Selected) != 0; bool isDisabled = (itemState & DrawItemState.Disabled) != 0; bool isChecked = (itemState & DrawItemState.Checked) != 0; Bitmap bmp = null; // Determine the bitmap to use if checked, radio-checked, normal if (isChecked == true) { if (item.RadioCheck) { bmp = (Bitmap)GetEmbeddedImage(this.RadioCheckIcon); } else { bmp = (Bitmap)GetEmbeddedImage(this.CheckIcon); } } else { if (item.RadioCheck) { bmp = (Bitmap)GetEmbeddedImage(this.RadioUnCheckIcon); } else { if (menuItemIconCollection.ContainsKey(item)) { bmp = (Bitmap)GetEmbeddedImage(menuItemIconCollection[item]); } } } // if no valid bitmap is found, exit. if (bmp == null) { return; } // Make the bitmap transparent bmp.MakeTransparent(); // Render the bitmap (the bitmap is grayed out if the // item is disabled) if (isDisabled == true) { ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(0.2F); Rectangle tmpRect = new Rectangle((int)BitmapBounds.X + 2, (int)BitmapBounds.Y + 2, (int)BitmapBounds.Width - 2, (int)BitmapBounds.Right - 2); g.DrawImage(bmp, tmpRect, 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, imageAttr); imageAttr.ClearGamma(); } else { g.DrawImage(bmp, BitmapBounds.X + 2, BitmapBounds.Y + 2); } // Free the resource. bmp.Dispose(); }
// *********************************************************************** // HELPER: DrawBackground // INPUT : Graphics, state of the item // NOTES : Fills the background of the item including the bitmap area public void DrawBackground(Graphics g, DrawItemState itemState) { // some helper variables Brush backBrush = null; Brush bitmapBrush = null; Pen borderPen = null; bool selected, disabled, paintBitmapArea; Rectangle rectToPaint; // Determine the state of the item selected = ((itemState & DrawItemState.Selected) > 0); disabled = ((itemState & DrawItemState.Disabled) > 0); // Determine whether the bitmap vertical strip must be created paintBitmapArea = !(BitmapBackColorStart.Equals(Color.Empty) && BitmapBackColorEnd.Equals(Color.Empty)); if (paintBitmapArea) { rectToPaint = Rectangle.Round(ItemBounds); } else { rectToPaint = Rectangle.Round(MenuItemBounds); } // Determine the brushes to use based on the state if (selected && !disabled) { if (SpecialBackColorSelected) { backBrush = new LinearGradientBrush(rectToPaint, MenuItemBackColorSelectedStart, MenuItemBackColorSelectedEnd, LinearGradientMode.Horizontal); } else { backBrush = new SolidBrush(MenuItemBackColorSelected); } borderPen = new Pen(MenuItemBorderSelected); } else { if (MenuItemDithered) { backBrush = new LinearGradientBrush(rectToPaint, MenuItemBackColorStart, MenuItemBackColorEnd, LinearGradientMode.Horizontal); borderPen = null; } else { backBrush = new SolidBrush(MenuItemBackColorStart); } } // Fill the area // NOTE: // When you fill an area larger than the linear gradient, the // end color is used to fill it. This ensures that we also have // the bitmap area painted with the end color of the gradient. // This is for free if ((selected && !disabled)) { rectToPaint = Rectangle.Round(MenuItemBounds); g.FillRectangle(backBrush, rectToPaint); bitmapBrush = new SolidBrush(MenuItemBackColorSelectedStart); // dessine pour la zone du bitmap une couleur identique g.FillRectangle(bitmapBrush, BitmapBounds); // Draw border rectToPaint.Width -= 1; rectToPaint.Height -= 1; g.DrawRectangle(borderPen, rectToPaint); } else { g.FillRectangle(backBrush, rectToPaint); if (paintBitmapArea) { bitmapBrush = new LinearGradientBrush(BitmapBounds, __BitmapBackColorStart, __BitmapBackColorEnd, LinearGradientMode.Horizontal); g.FillRectangle(bitmapBrush, BitmapBounds); } } // Cleanup objects if (!(bitmapBrush == null)) { bitmapBrush.Dispose(); } backBrush.Dispose(); if (!(borderPen == null)) { borderPen.Dispose(); } }
public DrawSubItemEventArgs(Graphics graphics,Font font,Rectangle rect,int index,int subIndex,PropertyDescriptor boundProperty,DrawItemState state) : base(graphics,font,rect,index,state) { this.subIndex = subIndex; this.boundProperty = boundProperty; }
private Brush GetComboBoxItemBrush( ComputerName computer, DrawItemState state ) { if ( (state & DrawItemState.Selected) != 0 ) return SystemBrushes.HighlightText; else if ( computer.Alias != null ) return UIItems.AliasBrush; else return SystemBrushes.ControlText; }
protected internal abstract Size MeasureTabStripTab(Graphics graphics, Image image, string text, Font font, DrawItemState state);