private void OnPaintStandard(PaintEventArgs e) { SolidBrush ctrlBrush = null; if (Enabled) { if (ReadOnly) { if (BackColor.ToKnownColor() == KnownColor.Window) { ctrlBrush = new SolidBrush(Color.FromKnownColor(KnownColor.Control)); } else { ctrlBrush = new SolidBrush(BackColor); } } else { ctrlBrush = new SolidBrush(BackColor); } } else { if (BackColor.ToKnownColor() == KnownColor.Window) { ctrlBrush = new SolidBrush(Color.FromKnownColor(KnownColor.Control)); } else { ctrlBrush = new SolidBrush(BackColor); } } using ( ctrlBrush ) { e.Graphics.FillRectangle(ctrlBrush, ClientRectangle); } switch (BorderStyle) { case BorderStyle.Fixed3D: ControlPaint.DrawBorder3D(e.Graphics, ClientRectangle, Border3DStyle.Sunken); break; case BorderStyle.FixedSingle: ControlPaint.DrawBorder(e.Graphics, ClientRectangle, Color.FromKnownColor(KnownColor.WindowFrame), ButtonBorderStyle.Solid); break; } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; Rectangle rect = e.ClipRectangle; // ブラシを作成 Brush brush = new SolidBrush(ValueColor); Brush blank = new SolidBrush(SystemColors.Control); // position(現在位置)から描画範囲を計算 float range = (float)(Math.Abs(Minimum) + Math.Abs(Maximum)); float pos = range != 0 ? ((float)Position / range) : 0; float right = rect.Width * pos; g.FillRectangle(brush, 0, 0, right, rect.Height); g.FillRectangle(blank, right, 0, rect.Width - right, rect.Height); // 数字を描画 StringFormat format = StringFormat.GenericDefault; Brush textbrush = new SolidBrush(ForeColor); string text = null; switch (style) { case ProgressTextStyle.Percent: text = Percent + "%"; break; case ProgressTextStyle.Length: text = String.Format("{0}/{1}", Position, Maximum); break; case ProgressTextStyle.None: text = String.Empty; break; } // 全体の中央に配置 format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; // 文字列を描画 g.DrawString(text, this.Font, textbrush, rect, format); // 境界線を描画 Rectangle bounds = new Rectangle(0, 0, Width, Height); ControlPaint.DrawBorder3D(g, bounds, BorderStyle); }
/// <summary> /// [email protected] : for FreezePanes enhancement, draw method is extended by adding a parameter to specify which border should be drawn. /// </summary> /// <param name="graphics"></param> /// <param name="area"></param> /// <param name="partType"></param> public override void Draw(GraphicsCache graphics, RectangleF area, BorderPartType partType) { Border3DSide sides = Border3DSide.All; if (partType == BorderPartType.All) { sides = Border3DSide.All; } if (BorderStyle == BorderStyle.System) { ControlPaint.DrawBorder3D(graphics.Graphics, Rectangle.Round(area), Border3DStyle.Flat, sides); } }
/// <summary> /// Draws a legacy style combo box control. /// </summary> /// <param name="graphics"></param> /// <param name="bounds"></param> /// <param name="buttonBounds"></param> /// <param name="backColor"></param> /// <param name="state"></param> internal static void DrawLegacyComboBox(Graphics graphics, Rectangle bounds, Rectangle buttonBounds, Color backColor, ButtonState state) { Rectangle borderRect = bounds; borderRect.Height++; graphics.FillRectangle(new SolidBrush(backColor), bounds); ControlPaint.DrawBorder3D(graphics, borderRect, Border3DStyle.Sunken); Rectangle buttonRect = buttonBounds; buttonRect.X -= 2; buttonRect.Y += 2; buttonRect.Height -= 3; ControlPaint.DrawComboButton(graphics, buttonRect, state); }
//============================================================================= // Events //============================================================================= //----------------------------------------------------------------------------- protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; if (Utility.Util.PaintingIsVisible(this, e)) { // draw an etched border. ControlPaint.DrawBorder3D(g, base.ClientRectangle, this.Border3DStyle); // if our parent has changed, hook its paint event. this.TrackedParent = this.Parent; } base.OnPaint(e); }
protected override void OnPaint(PaintEventArgs e) { switch (_borderType) { case BorderTypes.Left: { // To make a fake rectangle is because we are specifically looking for only a part of the rectangle which in this case is the left 2 however, we have to make it bigger for it to draw an entire left side with 2 pixels, I made it 8 just for safety. Rectangle _rectangle = new Rectangle(0, 0, 8, ClientRectangle.Height); ControlPaint.DrawBorder3D(e.Graphics, _rectangle, Border3DStyle.Sunken); break; } case BorderTypes.Right: { // This should put only the right 2 pixels of the border on the visible strip. Rectangle _rectangle = new Rectangle(-6, 0, 8, ClientRectangle.Height); ControlPaint.DrawBorder3D(e.Graphics, _rectangle, Border3DStyle.Sunken); break; } case BorderTypes.Top: { Rectangle _rectangle = new Rectangle(0, 0, ClientRectangle.Width, 8); ControlPaint.DrawBorder3D(e.Graphics, _rectangle, Border3DStyle.Sunken); break; } case BorderTypes.Bottom: { Rectangle _rectangle = new Rectangle(0, -6, ClientRectangle.Width, 8); ControlPaint.DrawBorder3D(e.Graphics, _rectangle, Border3DStyle.Sunken); break; } case BorderTypes.Square: { ControlPaint.DrawBorder3D(e.Graphics, ClientRectangle, Border3DStyle.SunkenInner); // e.Graphics.FillRectangle(SystemBrushes.Control, ClientRectangle); break; } default: { throw new ArgumentOutOfRangeException(); } } base.OnPaint(e); }
// protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) // { // Graphics gfx = e.Graphics; // //Border3DStyle b3dstyle = Border3DStyle.Bump; // //Border3DSide b3dside = Border3DSide.All; // // Rectangle rect = new Rectangle (0,0,this.Width,this.Height); // // // Dispose of brush resources after use // using (LinearGradientBrush lgb = new LinearGradientBrush(rect, gradientColorOne,gradientColorTwo,lgm)) // gfx.FillRectangle(lgb,rect); // // //3d border // //ControlPaint.DrawBorder3D(gfx,rect,b3dstyle,b3dside); // // // // Call the OnPaint method of the base class // base.OnPaint(e); // // } protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs e) { Graphics gfx = e.Graphics; Rectangle rect = new Rectangle(0, 0, this.Width, this.Height); // Dispose of brush resources after use using (LinearGradientBrush lgb = new LinearGradientBrush(rect, gradientColorOne, gradientColorTwo, lgm)) { gfx.FillRectangle(lgb, rect); } ControlPaint.DrawBorder3D(gfx, rect, b3dstyle); }
/// <summary> /// </summary> protected override void OnPaint(PaintEventArgs e) { if (DesignMode) { base.OnPaint(e); e.Graphics.DrawLine(Pens.Black, 0, 0, Width, Height); e.Graphics.DrawLine(Pens.Black, 0, Height, Width, 0); ControlPaint.DrawBorder3D(e.Graphics, ClientRectangle, Border3DStyle.Flat); } else { Render(e.Graphics); } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); foreach (TabButton button in buttons) { if (button.Bounds.IntersectsWith(e.ClipRectangle)) { DrawButton(e.Graphics, button); } } ControlPaint.DrawBorder3D(e.Graphics, ClientRectangle, borderStyle); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Draw the None and All buttons /// </summary> /// ------------------------------------------------------------------------------------ private void NoneAll_Paint(object sender, PaintEventArgs e) { Button button = sender as Button; Debug.Assert(button != null); Rectangle drawRect = button.ClientRectangle; Graphics g = e.Graphics; // draw the border and background of the button to look like // a text box. if (Application.RenderWithVisualStyles) { VisualStyleElement element = VisualStyleElement.TextBox.TextEdit.Normal; VisualStyleRenderer renderer = new VisualStyleRenderer(element); renderer.DrawBackground(g, drawRect); } else { g.FillRectangle(SystemBrushes.Window, drawRect); ControlPaint.DrawBorder3D(g, drawRect, Border3DStyle.Sunken); } // Allow some border space. drawRect.Inflate(-2, -2); // If the panel has focus then draw the focus rectangle if (button.Focused) { ControlPaint.DrawFocusRectangle(g, drawRect); } drawRect.Inflate(-2, -2); // If the button is selected then draw a selection rectangle if (ButtonSelected(button)) { DrawRectangle(g, drawRect, SystemPens.Highlight, 2); } drawRect.Inflate(-3, -3); // draw a border box on the "all" button if (button == m_btnAll) { DrawRectangle(g, drawRect, SystemPens.WindowText, 1); } drawRect.Inflate(-3, -3); // draw some text lines to fill in the remaining space DrawTextLines(drawRect, g); }
protected override void OnPaint(PaintEventArgs e) { // draw the borders switch (BorderStyle) { case BorderStyle.FixedSingle: ControlPaint.DrawBorder(e.Graphics, ClientRectangle, ForeColor, ButtonBorderStyle.Solid); break; case BorderStyle.Fixed3D: ControlPaint.DrawBorder3D(e.Graphics, ClientRectangle, Border3DStyle.Sunken); break; } Rectangle innerRectangle = GetInsideViewPort(); // draw the background using (var brush = new SolidBrush(BackColor)) e.Graphics.FillRectangle(brush, innerRectangle); if (_texture != null && GridDisplayMode != ImageBoxGridDisplayMode.None) { switch (GridDisplayMode) { case ImageBoxGridDisplayMode.Image: Rectangle fillRectangle = GetImageViewPort(); e.Graphics.FillRectangle(_texture, fillRectangle); if (!fillRectangle.Equals(innerRectangle)) { fillRectangle.Inflate(1, 1); ControlPaint.DrawBorder(e.Graphics, fillRectangle, ForeColor, ButtonBorderStyle.Solid); } break; case ImageBoxGridDisplayMode.Client: e.Graphics.FillRectangle(_texture, innerRectangle); break; } } // draw the image if (Image != null) { DrawImage(e.Graphics); } base.OnPaint(e); }
/// ------------------------------------------------------------------------------------ protected override void OnPaintBackground(PaintEventArgs e) { base.OnPaintBackground(e); if (!PaintingHelper.CanPaintVisualStyle()) { ControlPaint.DrawBorder3D(e.Graphics, ClientRectangle); } else { var renderer = new VisualStyleRenderer(GetVisualStyleTextBox()); renderer.DrawBackground(e.Graphics, ClientRectangle); } }
private void c1Sizer1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { // paint sizer grid foreach (Band row in this.c1Sizer1.Grid.Rows) { Rectangle rcrow = row.Bounds; foreach (Band col in this.c1Sizer1.Grid.Columns) { Rectangle rccol = col.Bounds; Rectangle rccel = Rectangle.Intersect(rcrow, rccol); ControlPaint.DrawBorder3D(e.Graphics, rccel, Border3DStyle.SunkenOuter); } } }
protected void DrawText(Graphics grfx) { if (!string.IsNullOrEmpty(titleText)) { var sf = new StringFormat { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center, FormatFlags = StringFormatFlags.NoWrap, Trimming = StringTrimming.EllipsisCharacter }; if (bIsMouseOverTitle) { grfx.DrawString(titleText, hoverTitleFont, new SolidBrush(hoverTitleColor), TitleRectangle, sf); } else { grfx.DrawString(titleText, normalTitleFont, new SolidBrush(normalTitleColor), TitleRectangle, sf); } } if (!string.IsNullOrEmpty(contentText)) { var sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center, FormatFlags = StringFormatFlags.MeasureTrailingSpaces, Trimming = StringTrimming.Word }; if (bIsMouseOverContent) { grfx.DrawString(contentText, hoverContentFont, new SolidBrush(hoverContentColor), ContentRectangle, sf); if (EnableSelectionRectangle) { ControlPaint.DrawBorder3D(grfx, RealContentRectangle, Border3DStyle.Etched, Border3DSide.Top | Border3DSide.Bottom | Border3DSide.Left | Border3DSide.Right); } } else { grfx.DrawString(contentText, normalContentFont, new SolidBrush(normalContentColor), ContentRectangle, sf); } } }
private void GradientEdit_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Rectangle gradientViewRect = getGradientViewRect(); // create an area for keys to be drawn in; although their tips // are drawn over the gradient display this defines the lower key section only Rectangle keyDrawArea = new Rectangle( gradientViewRect.Left, gradientViewRect.Height, gradientViewRect.Width, mGradientKeyHeight); // if the cache is empty, rebuild the gradient image if (mGradientCache == null) { rebuildGradientCache(); } // render the cached gradient image if available and area to render is of a usable size if (mGradientCache != null && (gradientViewRect.Height >= 1 && gradientViewRect.Width >= 1)) { // setup interp modes to make sure the single pixel image is stretched correctly e.Graphics.CompositingQuality = CompositingQuality.AssumeLinear; e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor; // stretch the image into the area reserved for the gradient e.Graphics.DrawImage( mGradientCache, gradientViewRect); } // draw a border around the gradient display ControlPaint.DrawBorder3D( e.Graphics, gradientViewRect, mBorderStyle); // draw all the keys for (Int32 i = 0; i < mGradientKeyCollection.Count; i++) { mGradientKeyCollection[i].Paint( e.Graphics, mKeyStyle, mGradientKeyWidth, keyDrawArea, (i == mGKeySelectedIndex)); } }
/* * DrawBorder */ /// <summary> /// Draws the border with the specified style. /// </summary> /// <param name="g"><see cref="T:System.Drawing.Graphics"/> to draw on.</param> /// <param name="rect">The rectangle to fit the border in.</param> /// <param name="borderColor">Border color.</param> /// <param name="borderStyle">Border style.</param> public static void DrawBorder(Graphics g, Rectangle rect, Color borderColor, NuGenBorderStyle borderStyle) { if (borderStyle == NuGenBorderStyle.None) { return; } SmoothingMode previousSmoothingMode = g.SmoothingMode; g.SmoothingMode = SmoothingMode.Default; if (borderStyle == NuGenBorderStyle.Bump || borderStyle == NuGenBorderStyle.Etched || borderStyle == NuGenBorderStyle.Flat || borderStyle == NuGenBorderStyle.Raised || borderStyle == NuGenBorderStyle.RaisedInner || borderStyle == NuGenBorderStyle.RaisedOuter || borderStyle == NuGenBorderStyle.Sunken || borderStyle == NuGenBorderStyle.SunkenInner || borderStyle == NuGenBorderStyle.SunkenOuter) { ControlPaint.DrawBorder3D(g, rect, (Border3DStyle)borderStyle); } else { using (SolidBrush sb = new SolidBrush(borderColor)) using (Pen p = new Pen(sb)) { switch (borderStyle) { case NuGenBorderStyle.Dashed: p.DashStyle = DashStyle.Dash; break; case NuGenBorderStyle.Dotted: p.DashStyle = DashStyle.Dot; break; case NuGenBorderStyle.Solid: p.DashStyle = DashStyle.Solid; break; } g.DrawRectangle(p, new Rectangle(rect.X, rect.Y, rect.Width - 1, rect.Height - 1)); } } g.SmoothingMode = previousSmoothingMode; }
/// <summary>Paints the rule.</summary> protected override void OnPaint(PaintEventArgs e) { // Create a local version of the graphics object for the Bevel. Graphics g = e.Graphics; Rectangle r = ClientRectangle; if (Style != BevelStyle.Flat) { Border3DStyle style = Border3DStyle.SunkenOuter; if (Style == BevelStyle.Raised) { style = Border3DStyle.RaisedInner; } // Draw the Bevel. switch (Shape) { case Border3DSide.All: ControlPaint.DrawBorder3D(g, r.Left, r.Top, r.Width, r.Height, style); break; case Border3DSide.Left: ControlPaint.DrawBorder3D(g, r.Left, r.Top, 2, r.Height, style); break; case Border3DSide.Top: ControlPaint.DrawBorder3D(g, r.Left, r.Top, r.Width, 2, style); break; case Border3DSide.Bottom: ControlPaint.DrawBorder3D(g, r.Left, r.Bottom - 2, r.Width, 2, style); break; case Border3DSide.Middle: break; case Border3DSide.Right: ControlPaint.DrawBorder3D(g, r.Right - 2, r.Top, 2, r.Height, style); break; default: Debug.Assert(false); break; } } // Calling the base class OnPaint base.OnPaint(e); }
private void _Paint(object sender, PaintEventArgs e) { for (var y = 0; y < _yCellsCount; y++) { for (var x = 0; x < _xCellsCount; x++) { e.Graphics.FillRectangle(_cells[x, y].Brush, _cells[x, y].Shape); if (_cellSize >= 20) { ControlPaint.DrawBorder3D(e.Graphics, _cells[x, y].Shape, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom); } } } }
private void DrawQuickCustomisationIconCore(CustomDrawEventArgs e, QuickCustomizationIcon icon, Rectangle bounds) { if (icon == null) { return; } ControlPaint.DrawBorder3D(e.Graphics, e.Bounds, Border3DStyle.RaisedInner); if (icon.Image == null) { icon.Image = Resources.Customization; } e.Graphics.PageUnit = GraphicsUnit.Pixel; e.Graphics.DrawImageUnscaled(icon.Image, treeList.ViewInfo.QuickCustomisationBounds); }
private void UCSignal_Paint(object sender, PaintEventArgs e) { if (signal == null) { return; } if (signal.input) { ControlPaint.DrawBorder3D(e.Graphics, ClientRectangle, Border3DStyle.Etched); } else { ControlPaint.DrawBorder3D(e.Graphics, ClientRectangle, Border3DStyle.Raised); } }
protected override void OnPaint(PaintEventArgs e) { using (var brush = new LinearGradientBrush(base.Bounds, BackColor, BackColor2, GradientMode)) e.Graphics.FillRectangle(brush, base.Bounds); var r = new Rectangle(base.Bounds.X, base.Bounds.Y, base.Width - 1, base.Height - 1); if (BorderStyle == BorderStyle.FixedSingle) { e.Graphics.DrawRectangle(SystemPens.WindowFrame, r); } else if (BorderStyle == BorderStyle.Fixed3D) { ControlPaint.DrawBorder3D(e.Graphics, r); } }
protected override void OnPaintBackground(PaintEventArgs e) { FetchInfoToDislayEventArgs eArgs = new FetchInfoToDislayEventArgs(-1); OnFetchInfoToDislay(eArgs); e.Graphics.FillRectangle(brushes.GetBrush(eArgs.Colors.BackgroundColor), ClientRectangle); if (show_border) { ControlPaint.DrawBorder3D (e.Graphics, ClientRectangle); } }
protected override void OnPaint(PaintEventArgs p) { var g = p.Graphics; var rect = new Rectangle(0, 0, Width, Height); using (var brush = new SolidBrush(BackColor)) { g.FillRectangle(brush, rect); } if (BorderStyle != StiBorderStyle.None) { ControlPaint.DrawBorder3D(g, rect, (Border3DStyle)BorderStyle); } }
/// <summary> /// Raises the Paint event. /// </summary> protected override void OnPaint(PaintEventArgs e) { // raise the Paint event base.OnPaint(e); Rectangle bottomRect = this.ClientRectangle; bottomRect.Y = this.Height - FOOTER_AREA_HEIGHT; bottomRect.Height = FOOTER_AREA_HEIGHT; e.Graphics.DrawRectangle(Pens.Red, bottomRect); ControlPaint.DrawBorder3D(e.Graphics, bottomRect, Border3DStyle.Etched, Border3DSide.Top); }
/// <summary> /// 绘制进度条的背景。 /// </summary> /// <param name="graphics"></param> /// <param name="cell"></param> /// <param name="rect"></param> private void DrawProgressBackground(Graphics graphics, TreeListCell cell, Rectangle rect) { if (Application.RenderWithVisualStyles) { var element = VisualStyleElement.ProgressBar.Bar.Normal; if (VisualStyleRenderer.IsElementDefined(element)) { new VisualStyleRenderer(element).DrawBackground(graphics, rect); return; } } graphics.FillRectangle(SystemBrushes.Window, rect); ControlPaint.DrawBorder3D(graphics, rect, Border3DStyle.Flat); }
protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e) { Rectangle rect = new Rectangle(0, 0, e.ToolStrip.Width - 1, e.ToolStrip.Height - 1); if (Application.RenderWithVisualStyles) { ControlPaint.DrawVisualStyleBorder(e.Graphics, rect); } else { ControlPaint.DrawBorder3D(e.Graphics, rect, Border3DStyle.Sunken); } }
/// <summary> /// Draws the chart (w/o background or grid, but with border) to the Graphics canvas /// </summary> /// <param name="g">Graphics</param> private void DrawChart(Graphics g) { int visibleValues = Math.Min(this.Width / valueSpacing, drawValues.Count); int startDisplay = Math.Min(drawValues.Count, chartOffset);; int stopDisplay = Math.Min(drawValues.Count, visibleValues + chartOffset); // Dirty little "trick": initialize the first previous Point outside the bounds Point[] previousPoint = new Point[4]; previousPoint[0] = new Point(Width + valueSpacing, Height); previousPoint[1] = new Point(Width + valueSpacing, Height); previousPoint[2] = new Point(Width + valueSpacing, Height); previousPoint[3] = new Point(Width + valueSpacing, Height); Point[] currentPoint = new Point[4]; // Only draw average line when possible (visibleValues) and needed (style setting) //if (visibleValues > 0 && perfChartStyle.ShowAverageLine) { // averageValue = 0; // DrawAverageLine(g); //} // Connect all visible values with lines for (int pt = 0; pt < 4; pt++) { if (perfChartPenStyles[pt].ShowPen) { GetMinMaxValueForRelativeMode(pt); for (int i = startDisplay; i < stopDisplay; i++) { currentPoint[pt].X = previousPoint[pt].X - valueSpacing; currentPoint[pt].Y = (int)CalcVerticalPosition(perfChartPenStyles[pt], drawValues[i].value[pt]); // Actually draw the line g.DrawLine(perfChartPenStyles[pt].ChartLinePen.Pen, previousPoint[pt], currentPoint[pt]); previousPoint[pt] = currentPoint[pt]; } } } // Draw current relative maximum value stirng //if (scaleMode == ScaleMode.Relative) { // SolidBrush sb = new SolidBrush(perfChartPenStyles[0].ChartLinePen.Color); // g.DrawString(currentMaxValue.ToString(), this.Font, sb, 4.0f, 2.0f); //} // Draw Border on top ControlPaint.DrawBorder3D(g, 0, 0, Width, Height, b3dstyle); }
private void NotifyCustomDrawToolBar(ref Message m) { m.Result = (IntPtr)NativeMethods.CDRF_DODEFAULT; NativeMethods.DLLVERSIONINFO dvi = new NativeMethods.DLLVERSIONINFO(); dvi.cbSize = Marshal.SizeOf(typeof(NativeMethods.DLLVERSIONINFO)); NativeMethods.DllGetVersion(ref dvi); if (dvi.dwMajorVersion < 6) { NativeMethods.LPNMTBCUSTOMDRAW tbcd = (NativeMethods.LPNMTBCUSTOMDRAW)m.GetLParam(typeof(NativeMethods.LPNMTBCUSTOMDRAW)); NativeMethods.RECT rc = tbcd.nmcd.rc; Rectangle rectangle = new Rectangle(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); using (Graphics graphics = Graphics.FromHdc(tbcd.nmcd.hdc)) { CommandBarItem item = items[tbcd.nmcd.dwItemSpec]; bool hot = ((tbcd.nmcd.uItemState & NativeMethods.CDIS_HOT) != 0); bool selected = ((tbcd.nmcd.uItemState & NativeMethods.CDIS_SELECTED) != 0); bool disabled = ((tbcd.nmcd.uItemState & NativeMethods.CDIS_DISABLED) != 0); CommandBarCheckBox checkBox = item as CommandBarCheckBox; if ((checkBox != null) && (checkBox.IsChecked)) { ControlPaint.DrawBorder3D(graphics, rectangle, Border3DStyle.SunkenOuter); } else if (selected) { ControlPaint.DrawBorder3D(graphics, rectangle, Border3DStyle.SunkenOuter); } else if (hot) { ControlPaint.DrawBorder3D(graphics, rectangle, Border3DStyle.RaisedInner); } Image image = item.Image; if (image != null) { Size size = image.Size; Point point = new Point(rc.left + ((rc.right - rc.left - size.Width) / 2), rc.top + ((rc.bottom - rc.top - size.Height) / 2)); NativeMethods.DrawImage(graphics, image, point, disabled); } m.Result = (IntPtr)NativeMethods.CDRF_SKIPDEFAULT; } } }
private void Redraw() { Graphics g = Graphics.FromHwnd(this.Handle); Icon icon; Rectangle iconRect; Rectangle borderRect; int textWidth; int newWidth; if (_hovered && _pressed) { icon = ButtonIcons.PressedIcon; } else if (_hovered) { icon = ButtonIcons.HoverIcon; } else { icon = ButtonIcons.NormalIcon; } textWidth = (int)g.MeasureString(this.Text, this.Font).Width; g.DrawString(this.Text, this.Font, Brushes.Black, 26F, 2F, StringFormat.GenericDefault); newWidth = textWidth + 25; iconRect = new Rectangle(0, 0, 24, 24); if (newWidth != this.Width) { this.Width = newWidth; } borderRect = this.Bounds; borderRect.Inflate(-1, -1); if (_hovered) { ControlPaint.DrawBorder3D(g, borderRect, Border3DStyle.RaisedOuter); } if (this.Focused) { ControlPaint.DrawFocusRectangle(g, borderRect); } g.DrawIcon(icon, iconRect); }
protected override void OnDrawItem(DrawItemEventArgs e) { base.OnDrawItem(e); Graphics graphics = e.Graphics; Rectangle bounds = e.Bounds; bool selected = ((e.State & DrawItemState.Selected) != 0); bool disabled = ((e.State & DrawItemState.Disabled) != 0); if (item is CommandBarSeparator) { Rectangle r = new Rectangle(bounds.X, bounds.Y + (bounds.Height / 2), bounds.Width, bounds.Height); ControlPaint.DrawBorder3D(graphics, r, Border3DStyle.Etched, Border3DSide.Top); } else { this.DrawImage(graphics, bounds, selected, disabled); int width = 6 + imageSize.Width; this.DrawBackground(graphics, new Rectangle(bounds.X + width, bounds.Y, bounds.Width - width, bounds.Height), selected); using (TextGraphics textGraphics = new TextGraphics(graphics)) { if ((this.Text != null) && (this.Text.Length != 0)) { Size size = textGraphics.MeasureText(this.Text, font); Point point = new Point(); point.X = bounds.X + 3 + imageSize.Width + 6; point.Y = bounds.Y + ((bounds.Height - size.Height) / 2); this.DrawText(textGraphics, this.Text, point, selected, disabled); } CommandBarButtonBase buttonBase = item as CommandBarButtonBase; if ((buttonBase != null) && (buttonBase.Shortcut != Keys.None)) { string text = TypeDescriptor.GetConverter(typeof(Keys)).ConvertToString(null, CultureInfo.InvariantCulture, buttonBase.Shortcut); Size size = textGraphics.MeasureText(text, font); Point point = new Point(); point.X = bounds.X + bounds.Width - 3 - imageSize.Width - 3 - size.Width; point.Y = bounds.Y + ((bounds.Height - size.Height) / 2); this.DrawText(textGraphics, text, point, selected, disabled); } } } }