/// <summary> /// 引发 System.Window.Forms.Control.Paint 事件。 /// </summary> /// <param name="e">包含事件数据的 System.Windows.Forms.PaintEventArgs。</param> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Color backColor = this.BackColor; if (!this._backColorChanged && !(base.Enabled && !this.ReadOnly)) { backColor = SystemColors.Control; } e.Graphics.FillRectangle(new SolidBrush(backColor), base.ClientRectangle); Rectangle bounds = new Rectangle(base.ClientRectangle.Left, base.ClientRectangle.Top, base.ClientRectangle.Width - 1, base.ClientRectangle.Height - 1); switch (this.BorderStyle) { case BorderStyle.FixedSingle: ControlPaint.DrawBorder(e.Graphics, base.ClientRectangle, SystemColors.WindowFrame, ButtonBorderStyle.Solid); break; case BorderStyle.Fixed3D: if (!Application.RenderWithVisualStyles) { ControlPaint.DrawBorder3D(e.Graphics, base.ClientRectangle, Border3DStyle.Sunken); break; } ControlPaint.DrawVisualStyleBorder(e.Graphics, bounds); break; } }
protected override void WndProc(ref Message m) { base.WndProc(ref m); if (m.Msg == WM_PAINT) { Graphics graphics = CreateGraphics(); Rectangle rect = this.ClientRectangle; if (_CustomBorderColor != Color.FromArgb(171, 173, 179)) { var pen = new System.Drawing.Pen(_CustomBorderColor); try { graphics.DrawRectangle(pen, 0, 0, this.Width - 1, this.Height - 1); } finally { pen.Dispose(); } } else { ControlPaint.DrawVisualStyleBorder(graphics, new Rectangle(0, 0, this.Width - 1, this.Height - 1)); } } }
protected override void DrawBackground(PaintEventArgs e) { Rectangle rect = ClientRectangle; e.Graphics.FillRectangle(new SolidBrush(BackColor), rect); ControlPaint.DrawVisualStyleBorder(e.Graphics, new Rectangle(rect.X, rect.Y, rect.Width - 1, rect.Height - 1)); }
/// <summary> /// WndProcメソッドオーバーライド /// </summary> /// <param name="m"></param> #region "WndProc" protected override void WndProc(ref System.Windows.Forms.Message m) { base.WndProc(ref m); if ((m.Msg == WM_PAINT)) { using (Graphics g = CreateGraphics()) { if (_CustomBorderColor == Color.Empty) { return; } else if (_CustomBorderColor != DEFAULT_BODER_COLOR) { // 標準カラーでない場合は指定色で描画する System.Drawing.Pen p = new System.Drawing.Pen(_CustomBorderColor); g.DrawRectangle(p, 0, 0, this.Width - 1, this.Height - 1); } else { ControlPaint.DrawVisualStyleBorder(g, new Rectangle(0, 0, this.Width - 1, this.Height - 1)); } } } }
internal static void PaintColorLegendItem(ToolStripItem Item, PaintEventArgs e) { if (Item != null) { //Make our outermost painting rect a little smaller. Rectangle R = e.ClipRectangle; R.Inflate(-1, -1); //Paint the background. Graphics G = e.Graphics; using (Brush B = new SolidBrush(Item.BackColor)) { G.FillRectangle(B, R); } //Draw a border. Rectangle BorderRect = new Rectangle(R.X, R.Y, R.Width - 1, R.Height - 1); ControlPaint.DrawVisualStyleBorder(G, BorderRect); //Draw the image centered. (I should probably check the //item's ImageAlign property here, but I know I'm always //using MiddleCenter for all the passed-in items.) Image I = Item.Image; Rectangle ImageRect = new Rectangle(R.X + (R.Width - I.Width) / 2, R.Y + (R.Height - I.Height) / 2, I.Width, I.Height); G.DrawImage(I, ImageRect); } }
private void TestRunnerControl_Paint(object sender, PaintEventArgs e) { Rectangle r = targetsPanel.Bounds; r.Inflate(1, 1); ControlPaint.DrawVisualStyleBorder(e.Graphics, r); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (this.DrawVisualStyleBorder) { ControlPaint.DrawVisualStyleBorder(e.Graphics, new Rectangle(0, 0, this.Width - 1, this.Height - 1)); } }
private void DrawLoadingBar(string title, Graphics g) { Font font = new Font("Arial", 16.0f, FontStyle.Bold); SizeF textSize = g.MeasureString(title, font); g.DrawString(title, font, Brushes.Black, (int)(this.ScreenSize.Width / 2) - (textSize.Width / 2), (int)(this.ScreenSize.Height / 2) - (textSize.Height / 2) - 25); ControlPaint.DrawVisualStyleBorder(g, new Rectangle((int)(this.ScreenSize.Width / 2) - 100, (int)(this.ScreenSize.Height / 2) - 10, 200, 20)); LinearGradientBrush brush = new LinearGradientBrush(new Rectangle((int)(this.ScreenSize.Width / 2) - 100, (int)(this.ScreenSize.Height / 2) - 10, 200, 20), Color.Yellow, Color.Black, LinearGradientMode.Vertical); g.FillRectangle(brush, (this.ScreenSize.Width / 2) - 100, (this.ScreenSize.Height / 2) - 10, loading * 2, 20); }
protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; g.FillRectangle(Enabled ? SystemBrushes.Window : SystemBrushes.Control, DisplayRectangle); if (Enabled) { ControlPaint.DrawVisualStyleBorder(g, new Rectangle(0, 0, Width - 1, Height - 1)); } else { g.DrawRectangle(SystemPens.InactiveBorder, new Rectangle(0, 0, Width - 1, Height - 1)); } }
protected override void OnPaint(PaintEventArgs e) { e.Graphics.Clear(InternalTextBox.BackColor); //base.OnPaint(e); Graphics grf = e.Graphics; //grf.FillRectangle(SystemBrushes.Window, ClientRectangle); //grf.DrawRectangle(SystemPens.ActiveCaption, 0, 0, ClientSize.Width - 1, ClientSize.Height - 1); ControlPaint.DrawVisualStyleBorder(grf, new Rectangle(0, 0, Width - 1, Height - 1)); //Rectangle rect = Tb.Bounds; //grf.FillRectangle(SystemBrushes.Window, rect); //ControlPaint.DrawVisualStyleBorder(grf, new Rectangle(rect.Left - 1, rect.Top - 1, rect.Width + 1, rect.Height + 1)); }
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); } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaintBackground(e); if (this.BorderStyle == System.Windows.Forms.BorderStyle.FixedSingle) { ControlPaint.DrawBorder(e.Graphics, new Rectangle(0, 0, base.ClientRectangle.Width - 1, base.ClientRectangle.Height - 1), this._borderColor, ButtonBorderStyle.Solid); } else if (VisualStyleRenderer.IsSupported && Application.RenderWithVisualStyles) { ControlPaint.DrawVisualStyleBorder(e.Graphics, new Rectangle(0, 0, base.ClientRectangle.Width - 1, base.ClientRectangle.Height - 1)); } else { ControlPaint.DrawBorder3D(e.Graphics, new Rectangle(0, 0, base.ClientRectangle.Width - 1, base.ClientRectangle.Height - 1), Border3DStyle.Sunken); } }
protected override void OnPaint(PaintEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } base.OnPaint(e); Color backColor = BackColor; if (!_backColorChanged) { if (!Enabled || ReadOnly) { backColor = SystemColors.Control; } } using (SolidBrush backgroundBrush = new SolidBrush(backColor)) { e.Graphics.FillRectangle(backgroundBrush, ClientRectangle); } Rectangle rectBorder = new Rectangle(ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Width - 1, ClientRectangle.Height - 1); switch (BorderStyle) { case BorderStyle.Fixed3D: if (Application.RenderWithVisualStyles) { ControlPaint.DrawVisualStyleBorder(e.Graphics, rectBorder); } else { ControlPaint.DrawBorder3D(e.Graphics, ClientRectangle, Border3DStyle.Sunken); } break; case BorderStyle.FixedSingle: ControlPaint.DrawBorder(e.Graphics, ClientRectangle, SystemColors.WindowFrame, ButtonBorderStyle.Solid); break; } }
/// <summary> /// Raises the <see cref="E:Paint" /> event. /// </summary> /// <param name="args">The <see cref="PaintEventArgs" /> instance containing the event data.</param> protected override void OnPaint(PaintEventArgs args) { base.OnPaint(args); // paint custom control borders if (BorderStyle == BorderStyleEx.VisualStyle) { if (Application.RenderWithVisualStyles) { ControlPaint.DrawVisualStyleBorder(args.Graphics, new Rectangle(0, 0, Width - 1, Height - 1)); } else { ControlPaint.DrawBorder3D(args.Graphics, new Rectangle(0, 0, Width, Height), Border3DStyle.SunkenOuter); ControlPaint.DrawBorder3D(args.Graphics, new Rectangle(1, 1, Width - 2, Height - 2), Border3DStyle.SunkenInner); } } }
/// <summary> /// Handles the custom painting for the control. /// </summary> /// <param name="e">The paint event arguments.</param> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (this.UseVisualStyleBorder) { Rectangle rectClient = this.ClientRectangle; Rectangle rectBorder = new(rectClient.X, rectClient.Y, rectClient.Width - 1, rectClient.Height - 1); if (Application.RenderWithVisualStyles) { ControlPaint.DrawVisualStyleBorder(e.Graphics, rectBorder); } else { ControlPaint.DrawBorder3D(e.Graphics, rectBorder, Border3DStyle.Sunken); } } }
private void Redraw() { myimage = new Bitmap(this.Width, this.Height); Graphics g = Graphics.FromImage(myimage); // Border if (Application.RenderWithVisualStyles) { ControlPaint.DrawVisualStyleBorder(g, new Rectangle(0, 0, this.Width - 1, this.Height - 1)); } else { ControlPaint.DrawBorder3D(g, new Rectangle(0, 0, this.Width, this.Height), Border3DStyle.RaisedOuter); } // triangles g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; // new brushes sbbrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Point(0, 0), new Point(this.Width, this.Height), SystemColors.ControlLight, SystemColors.ControlDarkDark); // upper triangle Point u1 = new Point(2, this.Height / 2 - 2); Point u2 = new Point(this.Width - 3, this.Height / 2 - 2); Point u3 = new Point(this.Width / 2, 2); g.DrawPolygon(sbpen, new Point[] { u1, u2, u3 }); g.FillPolygon(sbbrush, new Point[] { u1, u2, u3 }); // lower triangle Point l1 = new Point(2, this.Height / 2 + 1); Point l2 = new Point(this.Width - 3, this.Height / 2 + 1); Point l3 = new Point(this.Width / 2, this.Height - 3); g.DrawPolygon(sbpen, new Point[] { l3, l1, l2 }); g.FillPolygon(sbbrush, new Point[] { l1, l2, l3 }); }
/// <summary> /// Raises the <see cref="Control.Paint" /> event. /// </summary> /// <param name="e">A <see cref="PaintEventArgs" /> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (e != null) { Color backColor = Enabled ? BackColor : SystemColors.Control; using (SolidBrush backgroundBrush = new SolidBrush(backColor)) { e.Graphics.FillRectangle(backgroundBrush, ClientRectangle); } if (Application.RenderWithVisualStyles) { Rectangle border = new Rectangle(ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Width - 1, ClientRectangle.Height - 1); ControlPaint.DrawVisualStyleBorder(e.Graphics, border); } else { ControlPaint.DrawBorder3D(e.Graphics, ClientRectangle, Border3DStyle.Sunken); } } }
protected override void OnPaint(PaintEventArgs e) { if (ReadOnly && RelevanceInnerTextBoxReadOnly) { e.Graphics.Clear(SystemColors.Control); } else { e.Graphics.Clear(BackColor); } if (!InnerTextBox.Visible && !string.IsNullOrEmpty(Text)) { if (this.PasswordChar != 0) { e.Graphics.DrawString(new string(PasswordChar, this.Text.Length), Font, new SolidBrush(this.ForeColor), InnerTextBoxBounds, GetStringFormat()); } else { e.Graphics.DrawString(this.Text, Font, new SolidBrush(this.ForeColor), InnerTextBoxBounds, GetStringFormat()); } } foreach (TextBoxExItem item in Items) { if (item == null || !item.Visible) { continue; } item.OnPaint(e, BackColor, ForeColor, Font, item == HoverItem, item == PressedItem); } Rectangle rect = ClientRectangle; ControlPaint.DrawVisualStyleBorder(e.Graphics, new Rectangle(rect.Left, rect.Top, rect.Width - 1, rect.Height - 1)); }
protected override void OnPaint(PaintEventArgs e) { //base.OnPaint(e); e.Graphics.Clear(BackColor); Rectangle rect = ClientRectangle; // border ControlPaint.DrawVisualStyleBorder(e.Graphics, new Rectangle(0, 0, Width - 1, Height - 1)); rect.Inflate(-BorderSize, -BorderSize); int x0 = rect.X; int y0 = rect.Y; int index = 0; Point scroll = GetScrollPoint(); index += (scroll.Y / CellSize.Height) * ColumnCount + (scroll.X / CellSize.Width); y0 -= scroll.Y % CellSize.Height; x0 -= scroll.X % CellSize.Width; // int x = x0; int y = y0; Region old = e.Graphics.Clip; for (int i = index; i < Items.Count; i++) { Rectangle rectCell = new Rectangle(x, y, CellSize.Width, CellSize.Height); e.Graphics.Clip = new Region(Rectangle.Intersect(rectCell, rect)); if (i == HoverIndex) { DrawHover(rectCell, e); } bool selected = (MultiSelect && _SelectedIndexes.Contains(i)) || i == SelectedIndex; if (selected) { DrawSelection(rectCell, e); } Rectangle r2 = rectCell; r2.Inflate(-1, -1); DrawCell(i, r2, e); if (i % ColumnCount == ColumnCount - 1) { x = x0; y += CellSize.Height; } else { x += CellSize.Width; } if (y > rect.Bottom) { break; } } e.Graphics.Clip = old; // if (MultiSelect && IsMouseDown && !SelectionRect.IsEmpty) { e.Graphics.FillRectangle( new SolidBrush(Color.FromArgb(100, SystemColors.Highlight)), SelectionRect); e.Graphics.DrawRectangle(SystemPens.Highlight, SelectionRect.X, SelectionRect.Y, SelectionRect.Width - 1, SelectionRect.Height - 1); } }
private void GlyphTable_Paint(object sender, PaintEventArgs e) { Graphics gx = e.Graphics; Pen px = new Pen(Color.Black); gx.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y); gx.FillRectangle(new SolidBrush(BackColor), ClientRectangle); if (colCount < 1 && rowCount < 1) { return; } /// Draw Selection if (selectedAtCell != -1) { Rectangle selectedRect = rectangles[selectedAtCell]; LinearGradientBrush gdBrush = new LinearGradientBrush(selectedRect, focusColorEnd, focusColorStart, LinearGradientMode.Vertical); gx.FillRectangle(gdBrush, selectedRect); } StringFormat stringFormat = new StringFormat(StringFormat.GenericDefault); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; Font glyphFont = new Font(Font.Name, 12); Font hexFont = new Font("Tahmoa", 8); Brush foreBrush = new SolidBrush(ForeColor); Brush focusForeBrush = new SolidBrush(focusForeColor); Brush hexBrush = new SolidBrush(HexCodeColor); Brush focusHexForeBrush = new SolidBrush(focusHexForeColor); LinearGradientBrush cellBrush = new LinearGradientBrush(rectangles[0], cellColorEnd, cellColorStart, LinearGradientMode.Vertical); LinearGradientBrush alterBrush = new LinearGradientBrush(rectangles[0], alternateCellColorEnd, alternateCellColorStart, LinearGradientMode.Vertical); //foreach (CharacterRange glyphRange in glyphRanges) //{ // for (int i = 0; i < glyphRange.Length; i++) // { for (int i = 0; i < rectangles.Length && i < characters.Length; i++) { Rectangle cell = rectangles[i]; //Console.WriteLine("{0} {1} {2} {3}", e.ClipRectangle.X, e.ClipRectangle.Y, cell.X, cell.Y); if (gx.ClipBounds.IntersectsWith(cell) == false) { continue; } Brush textBrush; if (((i - i % NumberOfColumns) / NumberOfColumns) % 2 == 0 && selectedAtCell != i) { gx.FillRectangle(alterBrush, cell); } else if (selectedAtCell != i) { gx.FillRectangle(cellBrush, cell); } ControlPaint.DrawVisualStyleBorder(gx, cell); //draw character textBrush = selectedAtCell == i ? focusForeBrush : foreBrush; string character; if (char.MaxValue < characters[i]) { character = char.ConvertFromUtf32(characters[i]); } else { character = ((char)characters[i]).ToString(); } gx.DrawString(character, glyphFont, textBrush, new Rectangle(cell.X, cell.Y, cell.Width, cell.Height - (cell.Height / 3)), stringFormat); //draw hex notation textBrush = selectedAtCell == i ? focusHexForeBrush : hexBrush; gx.DrawString(characters[i].ToString(codeFormatStr), hexFont, textBrush, new Rectangle(cell.X, cell.Y + (cell.Height - (cell.Height / 3)), cell.Width, (cell.Height / 3)), stringFormat); } stringFormat.Dispose(); glyphFont.Dispose(); hexFont.Dispose(); px.Dispose(); /// Draw Border //ControlPaint.DrawBorder3D(gx, new Rectangle(0, 0, (colCount * colWidth) + 2, (rowCount * rowHeight) + 2)); }
/// <summary> /// Draws the dialog as a default MSR dialog. /// </summary> /// <param name="grfx">The <see cref="Graphics"/> context to draw on.</param> protected virtual void DrawDialogBackground(Graphics grfx) { if (mShowHeaderArea && Width > 0 && Height > 0) { int headerHeight = RescaleByDpiY(HEADER_AREA_HEIGHT); if (mHeaderColor != Color.Transparent && mHeaderColor != mContentColor) { using (Brush headerBrush = new SolidBrush(mHeaderColor)) { grfx.FillRectangle(headerBrush, new Rectangle( 0 , 0 , ClientRectangle.Width , headerHeight)); } ControlPaint.DrawVisualStyleBorder( grfx , new Rectangle( -SystemInformation.BorderSize.Width , -SystemInformation.BorderSize.Height , ClientRectangle.Width + SystemInformation.BorderSize.Width + SystemInformation.BorderSize.Width , headerHeight - 1)); } if (mDialogImage != null) { grfx.DrawImage( mDialogImage , new Rectangle( ClientRectangle.Width - mDialogImage.Width , (headerHeight - mDialogImage.Height) >> 1 , mDialogImage.Width , mDialogImage.Height) , new Rectangle( 0 , 0 , mDialogImage.Width , mDialogImage.Height) , GraphicsUnit.Pixel); } if (!string.IsNullOrEmpty(mDialogMainCaption)) { using (Font captionFont = new Font(Font.Name, 10.25F, FontStyle.Regular, GraphicsUnit.Point)) { using (Brush captionBrush = new SolidBrush(mHeaderCaptionColor)) { grfx.DrawString( mDialogMainCaption , captionFont , captionBrush , new Point( RescaleByDpiY(12) , RescaleByDpiY(8))); } } } if (!string.IsNullOrEmpty(mDialogMainDescription)) { using (Brush textBrush = new SolidBrush(mHeaderDescriptionColor)) { using (StringFormat sFormat = new StringFormat()) { int imgSpaceLeft = mDialogImage != null ? mDialogImage.Width : 0; grfx.DrawString( mDialogMainDescription , Font , textBrush , new RectangleF( RescaleByDpiY(24) , RescaleByDpiY(30) , ClientRectangle.Width - imgSpaceLeft - RescaleByDpiX(30) , headerHeight - RescaleByDpiY(22)) , sFormat); } } } } }