protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); PushButtonState state = PushButtonState.Normal; if (this.isPressed && RectangleToScreen(ClientRectangle).Contains(MousePosition)) { state = PushButtonState.Pressed; } else if (this.isHovering) { state = PushButtonState.Hot; } ButtonRenderer.DrawButton(e.Graphics, e.ClipRectangle, this.isFocused, state); Rectangle bounds = e.ClipRectangle; bounds.Inflate(-4, -4); bounds.Width -= 1; bounds.Height -= 1; using (SolidBrush brush = new SolidBrush(this.value)) { e.Graphics.FillRectangle(brush, bounds); } e.Graphics.DrawRectangle(SystemPens.GrayText, bounds); }
//override button appearance protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { if (!_enabledValue) { if ((paintParts & DataGridViewPaintParts.Background) == DataGridViewPaintParts.Background) { DrawCellBackground(ref graphics, cellStyle.BackColor, cellBounds); } if ((paintParts & DataGridViewPaintParts.Border) == DataGridViewPaintParts.Border) { PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } Rectangle buttonArea = cellBounds; SetButtonArea(ref buttonArea, ref advancedBorderStyle); ButtonRenderer.DrawButton(graphics, buttonArea, PushButtonState.Disabled); if (FormattedValue is String) { TextRenderer.DrawText(graphics, (string)FormattedValue, DataGridView.Font, buttonArea, SystemColors.GrayText); } } else { base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); } }
protected void PaintPanel(Graphics g, bool drawBorder = false) { if (Size.Width == 0 || Size.Height == 0) { return; } Rectangle bounds = new Rectangle(Point.Empty, Size); if (!Application.RenderWithVisualStyles) { g.FillRectangle(SystemBrushes.Control, bounds); } else { using (Brush b = new LinearGradientBrush(bounds, GradientStartColor, GradientEndColor, GradientMode)) { ButtonRenderer.DrawParentBackground(g, bounds, this); g.FillRectangle(b, bounds); } } if (drawBorder) { using (var p = new Pen(Program.TitleBarBorderColor)) g.DrawRectangle(p, new Rectangle(bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1)); } }
public override void Draw(DrawListViewSubItemEventArgs e) { if (_hot != Rectangle.Empty) { if (_hot != e.Bounds) { ListView.Invalidate(_hot); _hot = Rectangle.Empty; } } if ((!DrawIfEmpty) && (string.IsNullOrEmpty(e.SubItem.Text))) { return; } Point mouse = e.Item.ListView.PointToClient(Control.MousePosition); if ((ListView.GetItemAt(mouse.X, mouse.Y) == e.Item) && (e.Item.GetSubItemAt(mouse.X, mouse.Y) == e.SubItem)) { ButtonRenderer.DrawButton(e.Graphics, e.Bounds, e.SubItem.Text, Font, true, PushButtonState.Hot); _hot = e.Bounds; } else { ButtonRenderer.DrawButton(e.Graphics, e.Bounds, e.SubItem.Text, Font, false, PushButtonState.Normal); } }
private void PaintThemedButtonBackground(PaintEventArgs e, Rectangle bounds, bool up) { PushButtonState pbState = DetermineState(up); // First handle transparent case if (ButtonRenderer.IsBackgroundPartiallyTransparent(pbState)) { ButtonRenderer.DrawParentBackground(e, bounds, Control); } ButtonRenderer.DrawButtonForHandle( e, Control.ClientRectangle, false, pbState, DpiHelper.IsScalingRequirementMet ? Control.HandleInternal : IntPtr.Zero); // Now overlay the background image or backcolor (the former overrides the latter), leaving a margin. // We hardcode this margin for now since GetThemeMargins returns 0 all the time. // // Changing this because GetThemeMargins simply does not work in some cases. bounds.Inflate(-ButtonBorderSize, -ButtonBorderSize); //only paint if the user said not to use the themed backcolor. if (!Control.UseVisualStyleBackColor) { bool isHighContrastHighlighted = up && IsHighContrastHighlighted(); Color color = isHighContrastHighlighted ? SystemColors.Highlight : Control.BackColor; if (color.HasTransparency()) { using Brush brush = new SolidBrush(color); e.GraphicsInternal.FillRectangle(brush, bounds); } else { using var hdc = new DeviceContextHdcScope(e); hdc.FillRectangle( bounds, isHighContrastHighlighted ? User32.GetSysColorBrush(ColorTranslator.ToOle(color) & 0xFF) : Control.BackColorBrush); } } // This code is mostly taken from the non-themed rendering code path. if (Control.BackgroundImage != null && !DisplayInformation.HighContrast) { ControlPaint.DrawBackgroundImage( e.GraphicsInternal, Control.BackgroundImage, Color.Transparent, Control.BackgroundImageLayout, Control.ClientRectangle, bounds, Control.DisplayRectangle.Location, Control.RightToLeft); } }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.Paint" /> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (this.AllowPainting) { Control parent; this.OnPaintBackground(e); // if the parent is using a transparent color, it's likely to be something like a TabPage in a tab control // so we'll draw the parent background instead, to avoid having an ugly solid color parent = this.Parent; if (this.BackgroundImage == null && parent != null && (this.BackColor == parent.BackColor || parent.BackColor.A != 255)) { ButtonRenderer.DrawParentBackground(e.Graphics, this.DisplayRectangle, this); } if (_brush != null) { e.Graphics.FillPie(_brush, this.ClientRectangle, 0, 360); } e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; using (Pen pen = new Pen(this.BackColor, 2)) { e.Graphics.DrawEllipse(pen, new RectangleF(_centerPoint.X - _radius, _centerPoint.Y - _radius, _radius * 2, _radius * 2)); } if (!_color.IsEmpty) { this.PaintCurrentColor(e); } } }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.Paint" /> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (this.AllowPainting) { base.OnPaintBackground(e); // HACK: Easiest way of supporting things like BackgroundImage, BackgroundImageLayout etc // if the parent is using a transparent color, it's likely to be something like a TabPage in a tab control // so we'll draw the parent background instead, to avoid having an ugly solid color if (this.BackgroundImage == null && this.Parent != null && (this.BackColor == this.Parent.BackColor || this.Parent.BackColor.A != 255)) { ButtonRenderer.DrawParentBackground(e.Graphics, this.DisplayRectangle, this); } if (_brush != null) { e.Graphics.FillPie(_brush, this.ClientRectangle, 0, 360); } // HACK: smooth out the edge of the wheel. // https://github.com/cyotek/Cyotek.Windows.Forms.ColorPicker/issues/1 - the linked source doesn't do this hack yet draws with a smoother edge e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; using (Pen pen = new Pen(this.BackColor, 2)) { e.Graphics.DrawEllipse(pen, new RectangleF(_centerPoint.X - _radius, _centerPoint.Y - _radius, _radius * 2, _radius * 2)); } if (!this.Color.IsEmpty) { this.PaintCurrentColor(e); } } }
protected override void OnPaint(PaintEventArgs pevent) { if (!m_InternalPaint) { base.OnPaint(pevent); } else if (m_InternalPaint) { DrawSystemFlatstyle(pevent.Graphics); return; } m_InternalPaint = false; if (!Enabled) { m_State = PushButtonState.Disabled; } Graphics g = pevent.Graphics; ButtonRenderer.DrawButton(g, this.ClientRectangle, m_State); DrawSplitButton(g); if (!string.IsNullOrEmpty(m_Text)) { TextRenderer.DrawText(g, m_Text, Font, m_TextRectangle, ForeColor, m_TextFormatFlags); } if (m_State == PushButtonState.Normal && Focused) { ControlPaint.DrawFocusRectangle(g, m_TextRectangle); } }
protected override void OnPaint(PaintEventArgs e) { double mValue = 0; base.OnPaint(e); if (this.BackBuffer != null) { Graphics graphic = Graphics.FromImage(this.BackBuffer); graphic.DrawImage(this.BackImage, 0, 0); if (this.SliderHeight > 0) { //INSTANT VB TODO TASK: There is no VB equivalent to 'checked' in this context: //ORIGINAL LINE: if (this.m_Maximum - this.m_Minimum > 0 & checked(this.Height - this.SliderHeight) > 0) if (this.m_Maximum - this.m_Minimum > 0 && this.Height - this.SliderHeight > 0) { //INSTANT VB TODO TASK: There is no VB equivalent to 'checked' in this context: //ORIGINAL LINE: mValue = (this.m_Value - this.m_Minimum) / (this.m_Maximum - this.m_Minimum) * (double)(checked(this.Height - this.SliderHeight)); mValue = (this.m_Value - this.m_Minimum) / (this.m_Maximum - this.m_Minimum) * (double)(this.Height - this.SliderHeight); } //INSTANT VB TODO TASK: There is no VB equivalent to 'checked' in this context: //ORIGINAL LINE: Rectangle rectangle = new Rectangle(0, checked((int)Math.Round((double)(checked(this.Height - this.SliderHeight)) - mValue)), checked((int)Math.Round(this.SliderWidth)), this.SliderHeight); Rectangle rectangle = new Rectangle(0, Convert.ToInt32(Math.Truncate(Math.Round((double)(this.Height - this.SliderHeight) - mValue))), Convert.ToInt32(Math.Truncate(Math.Round(this.SliderWidth))), this.SliderHeight); ButtonRenderer.DrawButton(graphic, rectangle, PushButtonState.Normal); } e.Graphics.DrawImage(this.BackBuffer, 0, 0); } }
protected override void OnPaint(PaintEventArgs e) { //base.OnPaint(e); e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; ButtonRenderer.DrawParentBackground(e.Graphics, ClientRectangle, this); GraphicsPath path = new GraphicsPath(); if (!isPress) { path.AddLine(new PointF(0, ClientRectangle.Top - 2), new PointF(ClientRectangle.Width / 2, ClientRectangle.Bottom - 2) ); path.AddLine(new PointF(ClientRectangle.Width / 2, ClientRectangle.Bottom - 2), new PointF(ClientRectangle.Width, ClientRectangle.Top - 2)); } /*else * { * path.AddLine(new PointF(PenSize, ClientRectangle.Height - PenSize ), * new PointF(ClientRectangle.Width / wightDeliter - PenSize, PenSize) * ); * * path.AddLine(new PointF(ClientRectangle.Width / 2 - PenSize, PenSize), * new PointF(ClientRectangle.Width - PenSize, ClientRectangle.Height - PenSize) * ); * }*/ var Pen = new Pen(PenColor, PenSize); e.Graphics.DrawPath(Pen, path); }
protected override void OnPaint(PaintEventArgs e) { e.Graphics.Clear(BackColor); if (_ImageDefault == null) { if (DroppedDown) { ButtonRenderer.DrawButton(e.Graphics, new Rectangle(ClientRectangle.X - 1, ClientRectangle.Y - 1, ClientRectangle.Width + 2, ClientRectangle.Height + 2), PushButtonState.Pressed); } else { ButtonRenderer.DrawButton(e.Graphics, new Rectangle(ClientRectangle.X - 1, ClientRectangle.Y - 1, ClientRectangle.Width + 2, ClientRectangle.Height + 2), PushButtonState.Normal); } } if (_ImageDefault != null) { _ImageDefault.MakeTransparent(); e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; e.Graphics.DrawImage(_ImageDefault, 0, 0, ClientSize.Width, ClientSize.Height); } }
protected override void OnPaintBackground(PaintEventArgs e) { if ((base.BackColor == Color.Transparent && base.BackgroundImage == null) || _roundStyle == RoundStyle.None) { base.OnPaintBackground(e); } else { Graphics g = e.Graphics; using (GraphicsPath path = GraphicsPathHelper.CreatePath( base.ClientRectangle, _radius, _roundStyle, true)) { GraphicsState gState = g.Save(); g.SetClip(path); base.OnPaintBackground(e); g.Restore(gState); g.ExcludeClip(new Region(path)); ButtonRenderer.DrawParentBackground( g, base.ClientRectangle, this); g.ResetClip(); } } }
public override void Paint(Graphics graphics, bool focused, CustomButton.ButtonState state) { Rectangle r = new Rectangle(0, 0, _width, _height); switch (state) { case CustomButton.ButtonState.Normal: if (focused) { ButtonRenderer.DrawButton(graphics, r, false, System.Windows.Forms.VisualStyles.PushButtonState.Default); } else { ButtonRenderer.DrawButton(graphics, r, false, System.Windows.Forms.VisualStyles.PushButtonState.Normal); } break; case CustomButton.ButtonState.Hot: ButtonRenderer.DrawButton(graphics, r, focused, System.Windows.Forms.VisualStyles.PushButtonState.Hot); break; case CustomButton.ButtonState.Pressed: ButtonRenderer.DrawButton(graphics, r, false, System.Windows.Forms.VisualStyles.PushButtonState.Pressed); break; case CustomButton.ButtonState.Disabled: ButtonRenderer.DrawButton(graphics, r, false, System.Windows.Forms.VisualStyles.PushButtonState.Disabled); break; } }
/// <summary> /// Draws a combo box in the Windows Vista (and newer) style. /// </summary> /// <param name="graphics"></param> /// <param name="bounds"></param> /// <param name="state"></param> internal static void DrawComboBox(Graphics graphics, Rectangle bounds, ComboBoxState state) { var comboBounds = bounds; comboBounds.Inflate(1, 1); ButtonRenderer.DrawButton(graphics, comboBounds, GetPushButtonState(state)); var buttonBounds = new Rectangle( bounds.Left + (bounds.Width - 17), bounds.Top, 17, bounds.Height - (state != ComboBoxState.Pressed ? 1 : 0) ); var buttonClip = buttonBounds; buttonClip.Inflate(-2, -2); using (var oldClip = graphics.Clip.Clone()) { graphics.SetClip(buttonClip, CombineMode.Intersect); ComboBoxRenderer.DrawDropDownButton(graphics, buttonBounds, state); graphics.SetClip(oldClip, CombineMode.Replace); } }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { if (!this.enableValue) { if ((paintParts & DataGridViewPaintParts.Background) == DataGridViewPaintParts.Background) { SolidBrush cellBackground = new SolidBrush(cellStyle.BackColor); graphics.FillRectangle(cellBackground, cellBounds); cellBackground.Dispose(); } if ((paintParts & DataGridViewPaintParts.Border) == DataGridViewPaintParts.Border) { PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } Rectangle buttonArea = cellBounds; Rectangle buttonAdjustment = this.BorderWidths(advancedBorderStyle); buttonArea.X += buttonAdjustment.X; buttonArea.Y += buttonAdjustment.Y; buttonArea.Height -= buttonAdjustment.Height; buttonArea.Width -= buttonAdjustment.Width; ButtonRenderer.DrawButton(graphics, buttonArea, System.Windows.Forms.VisualStyles.PushButtonState.Disabled); if (this.FormattedValue is string) { TextRenderer.DrawText(graphics, (string)this.FormattedValue, this.DataGridView.Font, buttonArea, SystemColors.GrayText); } } else { base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); } }
//<Snippet2> //<Snippet4> // Draw the large or small button, depending on the current state. protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); // Draw the smaller pressed button image if (state == PushButtonState.Pressed) { // Set the background color to the parent if visual styles // are disabled, because DrawParentBackground will only paint // over the control background if visual styles are enabled. this.BackColor = Application.RenderWithVisualStyles ? Color.Azure : this.Parent.BackColor; // If you comment out the call to DrawParentBackground, // the background of the control will still be visible // outside the pressed button, if visual styles are enabled. ButtonRenderer.DrawParentBackground(e.Graphics, ClientRectangle, this); ButtonRenderer.DrawButton(e.Graphics, ClickRectangle, this.Text, this.Font, true, state); } // Draw the bigger unpressed button image. else { ButtonRenderer.DrawButton(e.Graphics, ClientRectangle, this.Text, this.Font, false, state); } }
void DrawButtonWithVisualStyles(PaintEventArgs e) { var textFormatFlags = TextFormatFlags.Default | TextFormatFlags.PreserveGraphicsClipping | TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.TextBoxControl | TextFormatFlags.VerticalCenter | TextFormatFlags.WordBreak; if (RightToLeft == RightToLeft.Yes) { textFormatFlags |= TextFormatFlags.Right | TextFormatFlags.RightToLeft; } ButtonRenderer.DrawButton( e.Graphics, HeaderRect, Text, Font, textFormatFlags, ButtonImage, ImageRect, Focused && ShowFocusCues, PushButtonState); }
private void DrawButton(PaintEventArgs e) { PushButtonState state = PushButtonState.Default; if (!this.Enabled) { state = PushButtonState.Disabled; } else if (this.IsPressed) { state = PushButtonState.Pressed; } else if (this.IsHovered) { state = PushButtonState.Hot; } else { state = PushButtonState.Normal; } TextFormatFlags format = this.GetTextFormat(); Rectangle bounds = new Rectangle(0, 0, this.Width, this.Height); //if (this.image != null) { // ButtonRenderer.DrawButton(e.Graphics, bounds,/* this.Text, this.Font, format, */this.image, // /this.imageBounds, this.Focused, state); //} //else { ButtonRenderer.DrawButton(e.Graphics, bounds, /* this.Text, this.Font, format, */ this.Focused, state); //} }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { if (!this.enabledValue) { if ((paintParts & DataGridViewPaintParts.Background) == DataGridViewPaintParts.Background) { SolidBrush solidBrush = new SolidBrush(cellStyle.BackColor); graphics.FillRectangle(solidBrush, cellBounds); solidBrush.Dispose(); } if ((paintParts & DataGridViewPaintParts.Border) == DataGridViewPaintParts.Border) { this.PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } Rectangle bounds = cellBounds; Rectangle rectangle = this.BorderWidths(advancedBorderStyle); bounds.X += rectangle.X; bounds.Y += rectangle.Y; bounds.Height -= rectangle.Height; bounds.Width -= rectangle.Width; ButtonRenderer.DrawButton(graphics, bounds, PushButtonState.Disabled); if (base.FormattedValue is string) { TextRenderer.DrawText(graphics, (string)base.FormattedValue, base.DataGridView.Font, bounds, SystemColors.GrayText); return; } } else { base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); } }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { // The button cell is disabled, so paint the border, // background, and disabled button for the cell. if (!_enabledValue) { // Draw the cell background, if specified. if ((paintParts & DataGridViewPaintParts.Background) == DataGridViewPaintParts.Background) { var cellBackground = new SolidBrush(cellStyle.BackColor); graphics.FillRectangle(cellBackground, cellBounds); cellBackground.Dispose(); } // Draw the cell borders, if specified. if ((paintParts & DataGridViewPaintParts.Border) == DataGridViewPaintParts.Border) { PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } // Calculate the area in which to draw the button. var buttonArea = cellBounds; var buttonAdjustment = BorderWidths(advancedBorderStyle); buttonArea.X += buttonAdjustment.X; buttonArea.Y += buttonAdjustment.Y; buttonArea.Height -= buttonAdjustment.Height; buttonArea.Width -= buttonAdjustment.Width; // Draw the disabled button. ButtonRenderer.DrawButton(graphics, buttonArea, PushButtonState.Disabled); // Draw the disabled button text. if (!(FormattedValue is String)) { return; } TextRenderer.DrawText(graphics, (string)FormattedValue, DataGridView.Font, buttonArea, SystemColors.GrayText); } else { // The button cell is enabled, so let the base class // handle the painting. base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); } }
protected virtual void PaintButton(Graphics graphics, int rowIndex, Rectangle cellBounds, DataGridViewAdvancedBorderStyle advancedBorderStyle) { Rectangle buttonArea = cellBounds; Rectangle buttonAdjustment = BorderWidths(advancedBorderStyle); buttonArea.X += buttonAdjustment.X; buttonArea.Y += buttonAdjustment.Y; buttonArea.Height -= buttonAdjustment.Height; buttonArea.Width -= buttonAdjustment.Width; Rectangle imageAdjustment; if (buttonArea.Width > buttonArea.Height) { float k = (buttonArea.Height - 2 * _buttonImageOffset) / (float)ButtonImage.Height; imageAdjustment = new Rectangle(0, 0, (int)(ButtonImage.Width * k), (int)(ButtonImage.Height * k)); } else { float k = (buttonArea.Width - 2 * _buttonImageOffset) / (float)ButtonImage.Width; imageAdjustment = new Rectangle(0, 0, (int)(ButtonImage.Width * k), (int)(ButtonImage.Height * k)); } int imgWidth = Math.Min(buttonArea.Width - 2 * _buttonImageOffset, imageAdjustment.Width); int imgHeight = Math.Min(buttonArea.Height - 2 * _buttonImageOffset, imageAdjustment.Height); Rectangle imageArea = new Rectangle( buttonArea.X + (buttonArea.Width - imgWidth) / 2, buttonArea.Y + (buttonArea.Height - imgHeight) / 2, imgWidth, imgHeight); ButtonRenderer.DrawButton(graphics, buttonArea, ButtonImage, imageArea, false, _hoveredRow == rowIndex ? PushButtonState.Hot : ButtonState); }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { base.Paint(graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); int width = 20; // 20 px buttonRect = new Rectangle(cellBounds.X + cellBounds.Width - width, cellBounds.Y, width, cellBounds.Height); cellLocation = cellBounds.Location; // to set image/ or some other properties to the filter button look at DrawButton overloads ButtonRenderer.DrawButton(graphics, buttonRect, "F", this.DataGridView.Font, false, currentState); }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.Paint" /> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (this.AllowPainting) { base.OnPaintBackground(e); if (this.BackgroundImage == null && this.Parent != null && (this.BackColor == this.Parent.BackColor || this.Parent.BackColor.A != 255)) { ButtonRenderer.DrawParentBackground(e.Graphics, this.DisplayRectangle, this); } if (_brush != null) { e.Graphics.FillPie(_brush, this.ClientRectangle, 0, 360); } // smooth out the edge of the wheel e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; using (Pen pen = new Pen(this.BackColor, 2)) { e.Graphics.DrawEllipse(pen, new RectangleF(_centerPoint.X - _radius, _centerPoint.Y - _radius, _radius * 2, _radius * 2)); } if (!this.Color.IsEmpty) { this.PaintCurrentColor(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) { if (_drawWithVisualStyles && _bufferedPainter.BufferedPaintSupported && _bufferedPainter.Enabled) { // draw in the vista/win7 style VisualStyleRenderer r = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal); r.DrawParentBackground(e.Graphics, ClientRectangle, this); Rectangle buttonBounds = ClientRectangle; buttonBounds.Inflate(1, 1); ButtonRenderer.DrawButton(e.Graphics, buttonBounds, GetPushButtonState(e.State)); Rectangle clipBounds = _dropDownButtonBounds; clipBounds.Inflate(-2, -2); e.Graphics.SetClip(clipBounds); ComboBoxRenderer.DrawDropDownButton(e.Graphics, _dropDownButtonBounds, e.State); e.Graphics.SetClip(ClientRectangle); } else if (_drawWithVisualStyles && ComboBoxRenderer.IsSupported) { // draw using the visual style renderer ComboBoxRenderer.DrawTextBox(e.Graphics, ClientRectangle, GetTextBoxState()); ComboBoxRenderer.DrawDropDownButton(e.Graphics, _dropDownButtonBounds, e.State); } else { // draw using the legacy technique DrawLegacyComboBox(e.Graphics, ClientRectangle, _dropDownButtonBounds, BackColor, GetPlainButtonState()); } OnPaintContent(new DropDownPaintEventArgs(e.Graphics, ClientRectangle, GetTextBoxBounds())); }
public void pnlSoftwarePreview_Paint(object sender, PaintEventArgs e) { if (Globals.Root == null) { return; } RectangleF destination = new RectangleF(0, 0, pnlSoftwarePreview.Width, pnlSoftwarePreview.Height); using (NetCanvas canvas = new NetCanvas(e.Graphics)) { switch (m_Style.ImageType) { case ButtonStyle.ImageTypes.RoundButton: ScalableImage.RoundButton((int)State).Draw(canvas, destination); break; case ButtonStyle.ImageTypes.GlassButton: ScalableImage.PaletteButton((int)State).Draw(canvas, destination); break; case ButtonStyle.ImageTypes.Windows: ButtonRenderer.DrawButton(e.Graphics, destination.ToRectangle(), false, ButtonStyle.WindowsPushButtonState(State)); break; } } }
protected override void OnPaint(PaintEventArgs pevent) { Graphics g = pevent.Graphics; // Fill the background ButtonRenderer.DrawParentBackground(g, ClientRectangle, this); // Paint the outer rounded rectangle g.SmoothingMode = SmoothingMode.AntiAlias; using (GraphicsPath outerPath = RoundedRectangle(buttonRect, 5, 0)) { using (LinearGradientBrush outerBrush = new LinearGradientBrush(buttonRect, gradientTop, gradientBottom, LinearGradientMode.Vertical)) { g.FillPath(outerBrush, outerPath); } using (Pen outlinePen = new Pen(gradientTop)) { g.DrawPath(outlinePen, outerPath); } } // Paint the highlight rounded rectangle using (GraphicsPath innerPath = RoundedRectangle(highlightRect, 5, 2)) { using (LinearGradientBrush innerBrush = new LinearGradientBrush(highlightRect, Color.FromArgb(highlightAlphaTop, Color.White), Color.FromArgb(highlightAlphaBottom, Color.White), LinearGradientMode.Vertical)) { g.FillPath(innerBrush, innerPath); } } // Paint the text TextRenderer.DrawText(g, Text, Font, buttonRect, ForeColor, Color.Transparent, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); ButtonRenderer.DrawButton(e.Graphics, ClientRectangle, Checked ? PushButtonState.Pressed : PushButtonState.Disabled); e.Graphics.DrawString(Flag, Font, Brushes.Black, ClientRectangle, new StringFormat { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center }); }
private static void PaintTransparentBackground(Control c, PaintEventArgs e) { if (c.Parent == null || !Application.RenderWithVisualStyles) { return; } ButtonRenderer.DrawParentBackground(e.Graphics, c.ClientRectangle, c); }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { //base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); // Draw the cell background, if specified. if ((paintParts & DataGridViewPaintParts.Background) == DataGridViewPaintParts.Background) { SolidBrush cellBackground = new SolidBrush(cellStyle.BackColor); if (this.OwningRow.Selected) { cellBackground = new SolidBrush(cellStyle.SelectionBackColor); } graphics.FillRectangle(cellBackground, cellBounds); cellBackground.Dispose(); } // Draw the cell borders, if specified. if ((paintParts & DataGridViewPaintParts.Border) == DataGridViewPaintParts.Border) { PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } //Daca nu avem imagine atunci nu desenam butonul if (ButtonImage != null) { // Calculate the area in which to draw the button. // Adjusting the following algorithm and values affects // how the image will appear on the button. Rectangle buttonArea = cellBounds; Rectangle buttonAdjustment = BorderWidths(advancedBorderStyle); buttonArea.X += buttonAdjustment.X; buttonArea.Y += buttonAdjustment.Y; buttonArea.Height -= buttonAdjustment.Height; buttonArea.Width -= buttonAdjustment.Width; Rectangle imageArea = new Rectangle( buttonArea.X + buttonArea.Width / 2 - 8 + LocalButtonImageOffset, buttonArea.Y + LocalButtonImageOffset, 16, 16); ButtonRenderer.DrawButton(graphics, buttonArea, ButtonImage, imageArea, false, ButtonState); } }
protected override void OnPaint(PaintEventArgs e) { if (Application.RenderWithVisualStyles) { ButtonRenderer.DrawParentBackground(e.Graphics, e.ClipRectangle, this); } else { base.OnPaintBackground(e); } if (Application.RenderWithVisualStyles) { TrackBarRenderer.DrawHorizontalTrack(e.Graphics, new Rectangle(e.ClipRectangle.Left + 5, 5 + (e.ClipRectangle.Height - 10 - 4) / 2, e.ClipRectangle.Width - 12, 4)); TrackBarRenderer.DrawHorizontalTicks(e.Graphics, new Rectangle(e.ClipRectangle.Left + 5, (e.ClipRectangle.Height - 5), e.ClipRectangle.Width - 12, 4), (Max + 1 - Min), EdgeStyle.Bump); TrackBarRenderer.DrawBottomPointingThumb(e.Graphics, GetThumbRectangle(), !Enabled ? TrackBarThumbState.Disabled : Pressed ? TrackBarThumbState.Pressed : Hot ? TrackBarThumbState.Hot : TrackBarThumbState.Normal); } else { e.Graphics.DrawRectangle(SystemPens.ControlDark, new Rectangle(e.ClipRectangle.Left + 5, 5 + (e.ClipRectangle.Height - 10 - 4) / 2, e.ClipRectangle.Width - 12, 3)); e.Graphics.DrawLine(SystemPens.ButtonHighlight, e.ClipRectangle.Left + 5, 5 + (e.ClipRectangle.Height - 8) / 2, e.ClipRectangle.Left + 5 + e.ClipRectangle.Width - 12, 5 + (e.ClipRectangle.Height - 8) / 2); e.Graphics.DrawLine(SystemPens.ControlDarkDark, e.ClipRectangle.Left + 6, 5 + (e.ClipRectangle.Height - 12) / 2, e.ClipRectangle.Left + 5 + e.ClipRectangle.Width - 13, 5 + (e.ClipRectangle.Height - 12) / 2); e.Graphics.DrawLine(SystemPens.ButtonFace, e.ClipRectangle.Left + 6, 5 + (e.ClipRectangle.Height - 14) / 2, e.ClipRectangle.Left + 5 + e.ClipRectangle.Width - 13, 5 + (e.ClipRectangle.Height - 14) / 2); Rectangle tickRect = new Rectangle(e.ClipRectangle.Left + 5, (e.ClipRectangle.Height - 5), e.ClipRectangle.Width - 10, 4); int tickLeft = tickRect.Left; int add = tickRect.Width / (Max - Min); using (Pen tickPen = new Pen(SystemColors.ControlText, 2.0f)) { for (int i = 0; i < (Max - Min) + 1; i++) { if (i < (Max - Min)) { add = (tickRect.Right - tickLeft) / (Max - (Min + i)); } e.Graphics.DrawLine(tickPen, tickLeft, tickRect.Bottom - 4, tickLeft, tickRect.Bottom); tickLeft += add; } } Rectangle thumbRect = GetThumbRectangle(); if (Pressed) { e.Graphics.FillPolygon(SystemBrushes.ControlDarkDark, new Point[] { new Point(thumbRect.Left, thumbRect.Top), new Point(thumbRect.Right, thumbRect.Top), new Point(thumbRect.Right, thumbRect.Bottom - 5), new Point(thumbRect.Left + thumbRect.Width / 2, thumbRect.Bottom), new Point(thumbRect.Left, thumbRect.Bottom - 5) }); e.Graphics.FillPolygon(SystemBrushes.ButtonHighlight, new Point[] { new Point(thumbRect.Left, thumbRect.Top), new Point(thumbRect.Right - 1, thumbRect.Top), new Point(thumbRect.Right - 1, thumbRect.Bottom - 5), new Point(thumbRect.Left + thumbRect.Width / 2, thumbRect.Bottom - 1), new Point(thumbRect.Left - 1 + thumbRect.Width / 2, thumbRect.Bottom - 1), new Point(thumbRect.Left, thumbRect.Bottom - 5) }); e.Graphics.FillPolygon(SystemBrushes.ButtonShadow, new Point[] { new Point(thumbRect.Left + 1, thumbRect.Top + 1), new Point(thumbRect.Right - 1, thumbRect.Top + 1), new Point(thumbRect.Right - 1, thumbRect.Bottom - 5), new Point(thumbRect.Left + thumbRect.Width / 2, thumbRect.Bottom - 1), new Point(thumbRect.Left + 1, thumbRect.Bottom - 5) }); e.Graphics.FillPolygon(SystemBrushes.ControlLightLight, new Point[] { new Point(thumbRect.Left + 1, thumbRect.Top + 1), new Point(thumbRect.Right - 2, thumbRect.Top + 1), new Point(thumbRect.Right - 2, thumbRect.Bottom - 5), new Point(thumbRect.Left + thumbRect.Width / 2, thumbRect.Bottom - 2), new Point(thumbRect.Left - 1 + thumbRect.Width / 2, thumbRect.Bottom - 2), new Point(thumbRect.Left + 1, thumbRect.Bottom - 5) }); } else { e.Graphics.FillPolygon(SystemBrushes.ControlDarkDark, new Point[] { new Point(thumbRect.Left, thumbRect.Top), new Point(thumbRect.Right, thumbRect.Top), new Point(thumbRect.Right, thumbRect.Bottom - 5), new Point(thumbRect.Left + thumbRect.Width / 2, thumbRect.Bottom), new Point(thumbRect.Left, thumbRect.Bottom - 5) }); e.Graphics.FillPolygon(SystemBrushes.ButtonHighlight, new Point[] { new Point(thumbRect.Left, thumbRect.Top), new Point(thumbRect.Right - 1, thumbRect.Top), new Point(thumbRect.Right - 1, thumbRect.Bottom - 5), new Point(thumbRect.Left + thumbRect.Width / 2, thumbRect.Bottom - 1), new Point(thumbRect.Left - 1 + thumbRect.Width / 2, thumbRect.Bottom - 1), new Point(thumbRect.Left, thumbRect.Bottom - 5) }); e.Graphics.FillPolygon(SystemBrushes.ButtonShadow, new Point[] { new Point(thumbRect.Left + 1, thumbRect.Top + 1), new Point(thumbRect.Right - 1, thumbRect.Top + 1), new Point(thumbRect.Right - 1, thumbRect.Bottom - 5), new Point(thumbRect.Left + thumbRect.Width / 2, thumbRect.Bottom - 1), new Point(thumbRect.Left + 1, thumbRect.Bottom - 5) }); e.Graphics.FillPolygon(SystemBrushes.ButtonFace, new Point[] { new Point(thumbRect.Left + 1, thumbRect.Top + 1), new Point(thumbRect.Right - 2, thumbRect.Top + 1), new Point(thumbRect.Right - 2, thumbRect.Bottom - 5), new Point(thumbRect.Left + thumbRect.Width / 2, thumbRect.Bottom - 2), new Point(thumbRect.Left - 1 + thumbRect.Width / 2, thumbRect.Bottom - 2), new Point(thumbRect.Left + 1, thumbRect.Bottom - 5) }); } } }