public GrupoPaint(IEnumerable<PintaEventHandler> capas) : this() { ControlPaint capa; foreach (PintaEventHandler metodo in capas) { capa=new ControlPaint(metodo); capa.Dock=DockStyle.Fill; capa.MouseClick+=OnClickEvent; this.capas.Add(capa); capa.BackColor=Color.Transparent;//las capas se tapan igual... } this.Controls.AddRange(this.capas.ToArray()); }
public new void Draw(Graphics g, PointF pntDrawOffset, Point pntMouseLocation, MouseButtons mbButtons) { GraphicsPath gpSeekPosition = new GraphicsPath(); gpSeekPosition.AddLine(new PointF(6.0F, 2), new PointF(this.SeekerBounds.Width - this.SeekerPosition * (this.SeekerBounds.Width - 15) - 5, 2)); gpSeekPosition.Widen(this.m_pOneWidth); this.DrawBwShape(g, gpSeekPosition, this.ButtonOpacity, 4.0F, Color.Black, ControlPaint.LightLight(Color.LightSeaGreen)); if (this.m_isMouseDown == true) { if (pntMouseLocation.X < pntDrawOffset.X) { this.SeekerPosition = 0.0F; } else if (pntMouseLocation.X > pntDrawOffset.X + this.SeekerBounds.Width - 15) { this.SeekerPosition = 1.0F; } else { this.SeekerPosition = (pntMouseLocation.X - pntDrawOffset.X - 6) / (this.SeekerBounds.Width - 15); } } float xBeginningOffset = pntDrawOffset.X; pntDrawOffset.X += this.SeekerPosition * (this.SeekerBounds.Width - 15); this.HotSpot = new RectangleF(-pntDrawOffset.X + xBeginningOffset, -15, this.SeekerBounds.Width, 20); base.Draw(g, pntDrawOffset, pntMouseLocation, mbButtons); gpSeekPosition.Dispose(); }
/// <summary> /// Draws the colorslider control using passed colors. /// </summary> /// <param name="e">The <see cref="T:System.Windows.Forms.PaintEventArgs"/> instance containing the event data.</param> /// <param name="thumbOuterColorPaint">The thumb outer color paint.</param> /// <param name="thumbInnerColorPaint">The thumb inner color paint.</param> /// <param name="thumbPenColorPaint">The thumb pen color paint.</param> /// <param name="barOuterColorPaint">The bar outer color paint.</param> /// <param name="barInnerColorPaint">The bar inner color paint.</param> /// <param name="barPenColorPaint">The bar pen color paint.</param> /// <param name="elapsedOuterColorPaint">The elapsed outer color paint.</param> /// <param name="elapsedInnerColorPaint">The elapsed inner color paint.</param> private void DrawColorSlider(PaintEventArgs e, Color thumbOuterColorPaint, Color thumbInnerColorPaint, Color thumbPenColorPaint, Color barOuterColorPaint, Color barInnerColorPaint, Color barPenColorPaint, Color elapsedOuterColorPaint, Color elapsedInnerColorPaint) { try { //set up thumbRect aproprietly if (barOrientation == Orientation.Horizontal) { int TrackX = (((trackerValue - barMinimum) * (ClientRectangle.Width - thumbSize)) / (barMaximum - barMinimum)); thumbRect = new Rectangle(TrackX, 1, thumbSize - 1, ClientRectangle.Height - 3); } else { int TrackY = (((trackerValue - barMinimum) * (ClientRectangle.Height - thumbSize)) / (barMaximum - barMinimum)); thumbRect = new Rectangle(1, TrackY, ClientRectangle.Width - 3, thumbSize - 1); } //adjust drawing rects barRect = ClientRectangle; thumbHalfRect = thumbRect; LinearGradientMode gradientOrientation; if (barOrientation == Orientation.Horizontal) { barRect.Inflate(-1, -barRect.Height / 3); barHalfRect = barRect; barHalfRect.Height /= 2; gradientOrientation = LinearGradientMode.Vertical; thumbHalfRect.Height /= 2; elapsedRect = barRect; elapsedRect.Width = thumbRect.Left + thumbSize / 2; } else { barRect.Inflate(-barRect.Width / 3, -1); barHalfRect = barRect; barHalfRect.Width /= 2; gradientOrientation = LinearGradientMode.Horizontal; thumbHalfRect.Width /= 2; elapsedRect = barRect; elapsedRect.Height = thumbRect.Top + thumbSize / 2; } //get thumb shape path GraphicsPath thumbPath; if (thumbCustomShape == null) { thumbPath = CreateRoundRectPath(thumbRect, thumbRoundRectSize); } else { thumbPath = thumbCustomShape; Matrix m = new Matrix(); m.Translate(thumbRect.Left - thumbPath.GetBounds().Left, thumbRect.Top - thumbPath.GetBounds().Top); thumbPath.Transform(m); } //draw bar using ( LinearGradientBrush lgbBar = new LinearGradientBrush(barHalfRect, barOuterColorPaint, barInnerColorPaint, gradientOrientation) ) { lgbBar.WrapMode = WrapMode.TileFlipXY; e.Graphics.FillRectangle(lgbBar, barRect); //draw elapsed bar using ( LinearGradientBrush lgbElapsed = new LinearGradientBrush(barHalfRect, elapsedOuterColorPaint, elapsedInnerColorPaint, gradientOrientation)) { lgbElapsed.WrapMode = WrapMode.TileFlipXY; if (Capture && drawSemitransparentThumb) { Region elapsedReg = new Region(elapsedRect); elapsedReg.Exclude(thumbPath); e.Graphics.FillRegion(lgbElapsed, elapsedReg); } else { e.Graphics.FillRectangle(lgbElapsed, elapsedRect); } } //draw bar band using (Pen barPen = new Pen(barPenColorPaint, 0.5f)) { e.Graphics.DrawRectangle(barPen, barRect); } } //draw thumb Color newthumbOuterColorPaint = thumbOuterColorPaint, newthumbInnerColorPaint = thumbInnerColorPaint; if (Capture && drawSemitransparentThumb) { newthumbOuterColorPaint = Color.FromArgb(175, thumbOuterColorPaint); newthumbInnerColorPaint = Color.FromArgb(175, thumbInnerColorPaint); } using ( LinearGradientBrush lgbThumb = new LinearGradientBrush(thumbHalfRect, newthumbOuterColorPaint, newthumbInnerColorPaint, gradientOrientation)) { lgbThumb.WrapMode = WrapMode.TileFlipXY; e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.FillPath(lgbThumb, thumbPath); //draw thumb band Color newThumbPenColor = thumbPenColorPaint; if (mouseEffects && (Capture || mouseInThumbRegion)) { newThumbPenColor = ControlPaint.Dark(newThumbPenColor); } using (Pen thumbPen = new Pen(newThumbPenColor)) { e.Graphics.DrawPath(thumbPen, thumbPath); } //gp.Dispose(); /*if (Capture || mouseInThumbRegion) * using (LinearGradientBrush lgbThumb2 = new LinearGradientBrush(thumbHalfRect, Color.FromArgb(150, Color.Blue), Color.Transparent, gradientOrientation)) * { * lgbThumb2.WrapMode = WrapMode.TileFlipXY; * e.Graphics.FillPath(lgbThumb2, gp); * }*/ } //draw focusing rectangle if (Focused & drawFocusRectangle) { using (Pen p = new Pen(Color.FromArgb(200, barPenColorPaint))) { p.DashStyle = DashStyle.Dot; Rectangle r = ClientRectangle; r.Width -= 2; r.Height--; r.X++; //ControlPaint.DrawFocusRectangle(e.Graphics, r); using (GraphicsPath gpBorder = CreateRoundRectPath(r, borderRoundRectSize)) { e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.DrawPath(p, gpBorder); } } } } catch (Exception Err) { Console.WriteLine("DrawBackGround Error in " + Name + ":" + Err.Message); } finally { } }
private void UserControl1_Paint(object sender, PaintEventArgs e) { e.Graphics.DrawImage(Resources.searchg, 3, (Height - 18) / 2, 18, 18); ControlPaint.DrawBorder(e.Graphics, ClientRectangle, Color.Gray, ButtonBorderStyle.Solid); }
void PaintWorker(PaintEventArgs e, bool up, CheckState state) { up = up && state == CheckState.Unchecked; ColorData colors = PaintRender(e.Graphics).Calculate(); LayoutData layout; if (Application.RenderWithVisualStyles) { //don't have the text-pressed-down effect when we use themed painting //this is for consistency with win32 app. layout = PaintLayout(e, true).Layout(); } else { layout = PaintLayout(e, up).Layout(); } Graphics g = e.Graphics; Button thisbutton = Control as Button; if (Application.RenderWithVisualStyles) { PaintThemedButtonBackground(e, Control.ClientRectangle, up); } else { Brush backbrush = null; if (state == CheckState.Indeterminate) { backbrush = CreateDitherBrush(colors.highlight, colors.buttonFace); } try { Rectangle bounds = Control.ClientRectangle; if (up) { // We are going to draw a 2 pixel border bounds.Inflate(-borderWidth, -borderWidth); } else { // We are going to draw a 1 pixel border. bounds.Inflate(-1, -1); } PaintButtonBackground(e, bounds, backbrush); } finally { if (backbrush != null) { backbrush.Dispose(); backbrush = null; } } } PaintImage(e, layout); //inflate the focus rectangle to be consistent with the behavior of Win32 app if (Application.RenderWithVisualStyles) { layout.focus.Inflate(1, 1); } if (up & IsHighContrastHighlighted()) { Color highlightTextColor = SystemColors.HighlightText; PaintField(e, layout, colors, highlightTextColor, false); if (Control.Focused && Control.ShowFocusCues) { // drawing focus rectangle of HighlightText color ControlPaint.DrawHighContrastFocusRectangle(g, layout.focus, highlightTextColor); } } else if (up & IsHighContrastHighlighted()) { PaintField(e, layout, colors, SystemColors.HighlightText, true); } else { PaintField(e, layout, colors, colors.windowText, true); } if (!Application.RenderWithVisualStyles) { Rectangle r = Control.ClientRectangle; if (Control.IsDefault) { r.Inflate(-1, -1); } DrawDefaultBorder(g, r, colors.windowFrame, Control.IsDefault); if (up) { Draw3DBorder(g, r, colors, up); } else { // contrary to popular belief, not Draw3DBorder(..., false); // ControlPaint.DrawBorder(g, r, colors.buttonShadow, ButtonBorderStyle.Solid); } } }
protected override void OnPaint(PaintEventArgs e) { //Debug.WriteLine("ClipRect: " + e.ClipRectangle); //e.Graphics.DrawRectangle(Pens.Red, e.ClipRectangle); var numColumns = GetNumberOfColumns(); var charWidth = (int)Font.Size; var rect = new Rectangle(0, 0, charWidth * 2, 24); if (e.ClipRectangle.Top == 0) { e.Graphics.FillRectangle(Brushes.LightGray, new Rectangle(0, 0, ClientRectangle.Width, 24)); for (int i = 0; i < numColumns; i++) { var num = (i); TextRenderer.DrawText(e.Graphics, num.ToString("X"), Font, rect, Color.Black, Color.Transparent, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter); ControlPaint.DrawBorder3D(e.Graphics, rect, Border3DStyle.RaisedInner); rect.X += charWidth * 2; } rect.X += charWidth; rect.Width = charWidth; for (int i = 0; i < numColumns; i++) { var num = ((i % 16)); TextRenderer.DrawText(e.Graphics, num.ToString("X"), Font, rect, Color.Black, Color.Transparent, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter); rect.X += charWidth; } } var lineX = (charWidth * 2) * numColumns; e.Graphics.DrawLine(Pens.Silver, lineX, 0, lineX, ClientRectangle.Bottom); int startRow = Math.Max(1, e.ClipRectangle.Top / 24); int endRow = e.ClipRectangle.Bottom / 24; int aidx, idx; aidx = idx = numColumns * (startRow + _scrollBar.Value - 1); for (int row = startRow; row < endRow; row++) { rect.Y = row * 24; rect.X = 0; rect.Width = charWidth * 2; for (int col = 0; col < numColumns; col++) { if (idx >= Data.Length) { return; } TextRenderer.DrawText(e.Graphics, Data[idx].ToString("X2"), Font, rect, ForeColor); idx++; rect.X += charWidth * 2; } rect.Width = charWidth; rect.X += charWidth; for (int col = 0; col < numColumns; col++) { char c = (char)Data[aidx]; if (c <= 32 || c >= 127) { c = '.'; } TextRenderer.DrawText(e.Graphics, c.ToString(), Font, rect, ForeColor); aidx++; rect.X += charWidth; } } }
protected virtual void OnPaintForeground(PaintEventArgs e) { Color borderColor, foreColor; if (useCustomForeColor) { foreColor = ForeColor; if (isHovered && !isPressed && Enabled) { borderColor = MetroPaint.BorderColor.CheckBox.Hover(Theme); } else if (isHovered && isPressed && Enabled) { borderColor = MetroPaint.BorderColor.CheckBox.Press(Theme); } else if (!Enabled) { borderColor = MetroPaint.BorderColor.CheckBox.Disabled(Theme); } else { borderColor = MetroPaint.BorderColor.CheckBox.Normal(Theme); } } else { if (isHovered && !isPressed && Enabled) { foreColor = MetroPaint.ForeColor.CheckBox.Hover(Theme); borderColor = MetroPaint.BorderColor.CheckBox.Hover(Theme); } else if (isHovered && isPressed && Enabled) { foreColor = MetroPaint.ForeColor.CheckBox.Press(Theme); borderColor = MetroPaint.BorderColor.CheckBox.Press(Theme); } else if (!Enabled) { foreColor = MetroPaint.ForeColor.CheckBox.Disabled(Theme); borderColor = MetroPaint.BorderColor.CheckBox.Disabled(Theme); } else { foreColor = !useStyleColors?MetroPaint.ForeColor.CheckBox.Normal(Theme) : MetroPaint.GetStyleColor(Style); borderColor = MetroPaint.BorderColor.CheckBox.Normal(Theme); } } Rectangle textRect = new Rectangle(16, 0, Width - 16, Height); Rectangle boxRect = new Rectangle(0, Height / 2 - 6, 12, 12); using (Pen p = new Pen(borderColor)) { switch (CheckAlign) { case ContentAlignment.TopLeft: boxRect = new Rectangle(0, 0, 12, 12); break; case ContentAlignment.MiddleLeft: boxRect = new Rectangle(0, Height / 2 - 6, 12, 12); break; case ContentAlignment.BottomLeft: boxRect = new Rectangle(0, Height - 13, 12, 12); break; case ContentAlignment.TopCenter: boxRect = new Rectangle(Width / 2 - 6, 0, 12, 12); textRect = new Rectangle(16, boxRect.Top + boxRect.Height - 5, Width - 16 / 2, Height); break; case ContentAlignment.BottomCenter: boxRect = new Rectangle(Width / 2 - 6, Height - 13, 12, 12); textRect = new Rectangle(16, -10, Width - 16 / 2, Height); break; case ContentAlignment.MiddleCenter: boxRect = new Rectangle(Width / 2 - 6, Height / 2 - 6, 12, 12); break; case ContentAlignment.TopRight: boxRect = new Rectangle(Width - 13, 0, 12, 12); textRect = new Rectangle(0, 0, Width - 16, Height); break; case ContentAlignment.MiddleRight: boxRect = new Rectangle(Width - 13, Height / 2 - 6, 12, 12); textRect = new Rectangle(0, 0, Width - 16, Height); break; case ContentAlignment.BottomRight: boxRect = new Rectangle(Width - 13, Height - 13, 12, 12); textRect = new Rectangle(0, 0, Width - 16, Height); break; } e.Graphics.DrawRectangle(p, boxRect); } if (Checked) { Color fillColor = CheckState == CheckState.Indeterminate ? borderColor : MetroPaint.GetStyleColor(Style); using (SolidBrush b = new SolidBrush(fillColor)) { Rectangle boxCheck = new Rectangle(boxRect.Left + 2, boxRect.Top + 2, 9, 9); e.Graphics.FillRectangle(b, boxCheck); } } TextRenderer.DrawText(e.Graphics, Text, MetroFonts.CheckBox(metroCheckBoxSize, metroCheckBoxWeight), textRect, foreColor, MetroPaint.GetTextFormatFlags(TextAlign, !this.AutoSize)); OnCustomPaintForeground(new MetroPaintEventArgs(Color.Empty, foreColor, e.Graphics)); if (displayFocusRectangle && isFocused) { ControlPaint.DrawFocusRectangle(e.Graphics, ClientRectangle); } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); int index = 0; int totalwidth = m_cols * (m_fieldSize.Width + m_spacing); int totalheight = m_rows * (m_fieldSize.Height + m_spacing); int offset = (m_spacing / 2 + 1); Rectangle r = new Rectangle(0, 0, totalwidth, totalheight); r.X += Padding.Left - offset; r.Y += Padding.Top - offset; e.Graphics.DrawRectangle(Pens.CadetBlue, r); r.X++; r.Y++; r.Width--; r.Height--; e.Graphics.FillRectangle(Brushes.White, r); for (int col = 1; col < m_cols; col++) { int x = Padding.Left - offset + (col * (m_fieldSize.Width + m_spacing)); e.Graphics.DrawLine(Pens.CadetBlue, x, r.Y, x, r.Bottom - 1); } for (int row = 1; row < m_rows; row++) { int y = Padding.Top - offset + (row * (m_fieldSize.Height + m_spacing)); e.Graphics.DrawLine(Pens.CadetBlue, r.X, y, r.Right - 1, y); } for (int row = 0; row < m_rows; row++) { for (int col = 0; col < m_cols; col++) { if (index >= m_colors.Count) { break; } Rectangle rect = GetRectangle(row, col); using (SolidBrush brush = new SolidBrush(m_colors[index++])) { e.Graphics.FillRectangle(brush, rect); } } } if (m_selindex >= 0) { Rectangle rect = GetSelectedItemRect(); e.Graphics.FillRectangle(Brushes.White, rect); rect.Inflate(-3, -3); using (SolidBrush brush = new SolidBrush(SelectedItem)) { e.Graphics.FillRectangle(brush, rect); } if (Focused) { rect.Inflate(2, 2); ControlPaint.DrawFocusRectangle(e.Graphics, rect); } else { rect.X -= 2; rect.Y -= 2; rect.Width += 3; rect.Height += 3; e.Graphics.DrawRectangle(Pens.CadetBlue, rect); } } }
void ResetColor(Label color, Control edit) { EditLineState newState = color.Tag as EditLineState; if (newState == null) { color.BackColor = this._tableLayoutPanel_main.BackColor; return; } if (newState.Active == true) { if (this.ContainsFocus == true) { color.BackColor = SystemColors.Highlight; Color focus_color = this.FocusedEditBackColor; if (edit != null && edit.BackColor != focus_color) { edit.BackColor = focus_color; } return; } else { if (this.m_bHideSelection == false) { color.BackColor = ControlPaint.Dark(SystemColors.Highlight); Color focus_color = ControlPaint.Light(this.FocusedEditBackColor); if (edit != null && edit.BackColor != focus_color) { edit.BackColor = focus_color; } return; } } } #if NO // 恢复原来的颜色 if (edit != null && edit.Tag != null) { Color back_color = (Color)edit.Tag; if (edit.BackColor != back_color) { edit.BackColor = back_color; } } #endif if (edit != null) { if (edit is TextBox) { TextBox textbox = edit as TextBox; if (textbox.ReadOnly == true && this.BackColor != Color.Transparent) { textbox.BackColor = this.BackColor; } else { edit.BackColor = _editBackColor; } } else { edit.BackColor = _editBackColor; } } if (newState.Changed == true) { color.BackColor = this.ColorChanged; } else { color.BackColor = this._tableLayoutPanel_main.BackColor; } }
private void DrawControl(Graphics graphics) { Graphics g = null; if (!this.Visible) { return; } // Bug reported by Kristoffer F if (this.Width < 1 || this.Height < 1) { return; } if (_Bitmap == null) { int iValueOffset = 0; int iScaleStartValue; // Create a bitmap _Bitmap = new Bitmap(this.Width, this.Height); g = Graphics.FromImage(_Bitmap); try { // Wash the background with BackColor g.FillRectangle(new SolidBrush(this.BackColor), 0, 0, _Bitmap.Width, _Bitmap.Height); if (this.StartValue >= 0) { iScaleStartValue = Convert.ToInt32(_StartValue * _Scale / _iMajorInterval); // Convert value to pixels } else { // If the start value is -ve then assume that we are starting just above zero // For example if the requested value -1.1 then make believe that the start is // +0.9. We can fix up the printing of numbers later. double dStartValue = Math.Ceiling(Math.Abs(_StartValue)) - Math.Abs(_StartValue); // Compute the offset that is to be used with the start point is -ve // This will be subtracted from the number calculated for the display numeral iScaleStartValue = Convert.ToInt32(dStartValue * _Scale / _iMajorInterval); // Convert value to pixels iValueOffset = Convert.ToInt32(Math.Ceiling(Math.Abs(_StartValue))); }; // Paint the lines on the image int iScale = _Scale; int iStart = Start(); // iStart is the pixel number on which to start. int iEnd = (this.Orientation == enumOrientation.orHorizontal) ? Width : Height; int iOffset = (int)Math.Ceiling((double)_StartOffset / _ZoomFactor / _iMajorInterval) * _Scale; for (int j = iStart - iOffset; j <= iEnd - iOffset + _Scale; j += iScale) { int iLeft = _Scale; // Make an assumption that we're starting at zero or on a major increment int jOffset = j + iScaleStartValue; iScale = ((jOffset - iStart) % _Scale); // Get the mod value to see if this is "big line" opportunity // If it is, draw big line if (iScale == 0) { if (_RulerAlignment != enumRulerAlignment.raMiddle) { if (this.Orientation == enumOrientation.orHorizontal) { Line(g, j, 0, j, Height); } else { Line(g, 0, j, Width, j); } } iLeft = _Scale; // Set the for loop increment } else { iLeft = _Scale - Math.Abs(iScale); // Set the for loop increment } iScale = iLeft; int iValue = (((jOffset - iStart) / _Scale) + 1) * _iMajorInterval; // Accommodate the offset if the starting point is -ve iValue -= iValueOffset; DrawValue(g, iValue, j - iStart + _StartOffset, iScale); int iUsed = 0; // TO DO: This must be wrong when the start is negative and not a whole number //Draw small lines for (int i = 0; i < _iNumberOfDivisions; i++) { // Get the increment for the next mark // Use a spreading algorithm rather that using expensive floating point numbers int iX = Convert.ToInt32(Math.Round((double)(_Scale - iUsed) / (double)(_iNumberOfDivisions - i), 0)); // So the next mark will have used up iUsed += iX; if (iUsed >= (_Scale - iLeft)) { iX = iUsed + j - (_Scale - iLeft) + _StartOffset; // Is it an even number and, if so, is it the middle value? bool bMiddleMark = ((_iNumberOfDivisions & 0x1) == 0) & (i + 1 == _iNumberOfDivisions / 2); bool bShowMiddleMark = bMiddleMark; bool bLastDivisionMark = (i + 1 == _iNumberOfDivisions); bool bLastAlignMiddleDivisionMark = bLastDivisionMark & (_RulerAlignment == enumRulerAlignment.raMiddle); bool bShowDivisionMark = !bMiddleMark & !bLastAlignMiddleDivisionMark; if (bShowMiddleMark) { DivisionMark(g, iX, _MiddleMarkFactor); // Height or Width will be 1/3 } else if (bShowDivisionMark) { DivisionMark(g, iX, _DivisionMarkFactor); // Height or Width will be 1/5 } } } } if (_i3DBorderStyle != Border3DStyle.Flat) { //ControlPaint.DrawBorder3D(g, this.ClientRectangle, this._i3DBorderStyle ); ControlPaint.DrawBorder3D(g, 0, 0, this.ClientRectangle.Width + 1, this.ClientRectangle.Height + 1, this._i3DBorderStyle); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } finally { g.Dispose(); } } g = graphics; try { // Always draw the bitmap g.DrawImage(_Bitmap, this.ClientRectangle); RenderTrackLine(g); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } finally { GC.Collect(); } }
private void labelNameview_Paint(object sender, PaintEventArgs e) { ControlPaint.DrawBorder(e.Graphics, labelNameview.DisplayRectangle, Color.White, ButtonBorderStyle.Solid); }
protected override void OnPaint(PaintEventArgs e) { //base.ItemHeight = GetPreferredSize(Size.Empty).Height; Color backColor, borderColor, foreColor; if (Parent != null) { backColor = Parent.BackColor; } else { backColor = Color.FromArgb(255, 255, 255); } if (isHovered && !isPressed && Enabled) { //foreColor = Color.FromArgb(17, 17, 17); //borderColor = Color.FromArgb(51, 51, 51); foreColor = Color.FromArgb(0, 120, 215); borderColor = Color.FromArgb(0, 120, 215); } else if (isHovered && isPressed && Enabled) { //foreColor = Color.FromArgb(153, 153, 153); //borderColor = Color.FromArgb(153, 153, 153); foreColor = Color.FromArgb(0, 120, 215); borderColor = Color.FromArgb(0, 120, 215); } else if (!Enabled) { //foreColor = Color.FromArgb(136, 136, 136); //borderColor = Color.FromArgb(204, 204, 204); foreColor = Color.FromArgb(17, 17, 17); borderColor = Color.FromArgb(51, 51, 51); } else { //foreColor = Color.FromArgb(153, 153, 153); //borderColor = Color.FromArgb(153, 153, 153); foreColor = Color.FromArgb(17, 17, 17); borderColor = Color.FromArgb(51, 51, 51); } e.Graphics.Clear(backColor); using (Pen p = new Pen(borderColor)) { Rectangle boxRect = new Rectangle(0, 0, Width - 1, Height - 1); e.Graphics.DrawRectangle(p, boxRect); } using (SolidBrush b = new SolidBrush(foreColor)) { e.Graphics.FillPolygon(b, new Point[] { new Point(Width - 20, (Height / 2) - 2), new Point(Width - 9, (Height / 2) - 2), new Point(Width - 15, (Height / 2) + 4) }); } Color textColor = Color.FromArgb(17, 17, 17); Rectangle textRect = new Rectangle(2, 2, Width - 20, Height - 4); TextRenderer.DrawText(e.Graphics, Text, Font, textRect, textColor, backColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter); if (false && isFocused) { ControlPaint.DrawFocusRectangle(e.Graphics, ClientRectangle); } }
/// <summary> /// Overrides the paint. /// </summary> /// <param name="e">A <see cref="PaintEventArgs"/> value.</param> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle, ColorTranslator.FromHtml("#7A7A7A"), ButtonBorderStyle.Solid); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); const int thumbPadding = 2; const int trackPadding = 2; var left = ClientRectangle.Left; var top = ClientRectangle.Top; var width = ClientRectangle.Width; var height = ClientRectangle.Height; var cursor = PointToClient(MousePosition); // paint focus rectangle if (ShowFocusRectangle && Focused) { ControlPaint.DrawFocusRectangle(e.Graphics, ClientRectangle); } if (!IsLeftMouseButtonDown()) { _thumbDragging = false; } // compute object bounds if (Orientation == Orientation.Horizontal) { _trackBounds = new Rectangle(left + trackPadding, top + height / 2 - _trackSize / 2, width - 2 * trackPadding, _trackSize); _thumbBounds = new Rectangle(ValueToPoint(Value).X - _thumbSize / 2, top + thumbPadding, _thumbSize, height - 2 * thumbPadding); } else { _trackBounds = new Rectangle(left + width / 2 - _trackSize / 2, top + trackPadding, _trackSize, height - 2 * trackPadding); _thumbBounds = new Rectangle(left + thumbPadding, ValueToPoint(Value).Y - _thumbSize / 2, width - 2 * thumbPadding, _thumbSize); } if (System.Windows.Forms.Application.RenderWithVisualStyles) { if (Orientation == Orientation.Horizontal) { // paint track var renderer = new VisualStyleRenderer(VisualStyleElement.TrackBar.Track.Normal); renderer.DrawBackground(e.Graphics, _trackBounds); // paint thumb if (!Enabled) { renderer.SetParameters(VisualStyleElement.TrackBar.Thumb.Disabled); } else if (_thumbDragging) { renderer.SetParameters(VisualStyleElement.TrackBar.Thumb.Pressed); } else if (!_thumbBounds.Contains(cursor)) { renderer.SetParameters(Focused ? VisualStyleElement.TrackBar.Thumb.Focused : VisualStyleElement.TrackBar.Thumb.Normal); } else { renderer.SetParameters(IsLeftMouseButtonDown() ? VisualStyleElement.TrackBar.Thumb.Pressed : VisualStyleElement.TrackBar.Thumb.Hot); } renderer.DrawBackground(e.Graphics, _thumbBounds); } else { // paint track var renderer = new VisualStyleRenderer(VisualStyleElement.TrackBar.TrackVertical.Normal); renderer.DrawBackground(e.Graphics, _trackBounds); // paint thumb if (!Enabled) { renderer.SetParameters(VisualStyleElement.TrackBar.ThumbVertical.Disabled); } else if (_thumbDragging) { renderer.SetParameters(VisualStyleElement.TrackBar.ThumbVertical.Pressed); } else if (!_thumbBounds.Contains(cursor)) { renderer.SetParameters(Focused ? VisualStyleElement.TrackBar.ThumbVertical.Focused : VisualStyleElement.TrackBar.ThumbVertical.Normal); } else { renderer.SetParameters(IsLeftMouseButtonDown() ? VisualStyleElement.TrackBar.ThumbVertical.Pressed : VisualStyleElement.TrackBar.ThumbVertical.Hot); } renderer.DrawBackground(e.Graphics, _thumbBounds); } } else { // paint track ControlPaint.DrawBorder3D(e.Graphics, _trackBounds, Border3DStyle.Sunken); // paint thumb if (!Enabled) { ControlPaint.DrawButton(e.Graphics, _thumbBounds, ButtonState.Inactive); } else { ControlPaint.DrawButton(e.Graphics, _thumbBounds, ButtonState.Normal); } } }
protected override void OnPaint(PaintEventArgs e) { var g = e.Graphics; var rect = new Rectangle(0, 0, ClientSize.Width, ClientSize.Height); var textColor = Colors.LightText; var borderColor = Colors.GreySelection; var fillColor = _useGenericBackColor ? (_isDefault ? Colors.DarkBlueBackground : Colors.LightBackground) : BackColor; var hoverColor = _useGenericBackColor ? (_isDefault ? Colors.BlueBackground : Colors.LighterBackground) : ControlPaint.Light(BackColor); if (Enabled) { switch (ButtonStyle) { case DarkButtonStyle.Normal: if (Focused && TabStop) { borderColor = Colors.BlueHighlight; } switch (ButtonState) { case DarkControlState.Hover: fillColor = hoverColor; break; case DarkControlState.Pressed: fillColor = Colors.DarkBackground; break; } break; case DarkButtonStyle.Flat: switch (ButtonState) { case DarkControlState.Normal: fillColor = Colors.GreyBackground; break; case DarkControlState.Hover: fillColor = Colors.MediumBackground; break; case DarkControlState.Pressed: fillColor = Colors.DarkBackground; break; } break; } } else { textColor = Colors.DisabledText; fillColor = Colors.DarkGreySelection; } using (var b = new SolidBrush(fillColor)) { g.FillRectangle(b, rect); } if (ButtonStyle == DarkButtonStyle.Normal) { using (var p = new Pen(borderColor, 1)) { var modRect = new Rectangle(rect.Left, rect.Top, rect.Width - 1, rect.Height - 1); g.DrawRectangle(p, modRect); } } var textOffsetX = 0; var textOffsetY = 0; if (Image != null) { var stringSize = g.MeasureString(Text, Font, rect.Size); var x = ClientSize.Width / 2 - Image.Size.Width / 2; var y = ClientSize.Height / 2 - Image.Size.Height / 2; switch (TextImageRelation) { case TextImageRelation.ImageAboveText: textOffsetY = Image.Size.Height / 2 + ImagePadding / 2; y = y - ((int)(stringSize.Height / 2) + ImagePadding / 2); break; case TextImageRelation.TextAboveImage: textOffsetY = (Image.Size.Height / 2 + ImagePadding / 2) * -1; y = y + (int)(stringSize.Height / 2) + ImagePadding / 2; break; case TextImageRelation.ImageBeforeText: textOffsetX = Image.Size.Width + ImagePadding / 2; x = ImagePadding; break; case TextImageRelation.TextBeforeImage: x = x + (int)stringSize.Width; break; } //g.DrawImage(Image, x, y); g.DrawImage(Image, new Rectangle(x, y, Image.Width, Image.Height)); } using (var b = new SolidBrush(textColor)) { var modRect = new Rectangle(rect.Left + textOffsetX + Padding.Left, rect.Top + textOffsetY + Padding.Top, rect.Width - Padding.Horizontal, rect.Height - Padding.Vertical); if (Image != null) { var stringFormat = new StringFormat { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Near, Trimming = StringTrimming.EllipsisCharacter }; g.DrawString(Text, Font, b, modRect, stringFormat); } else { var stringFormat = new StringFormat { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center, Trimming = StringTrimming.EllipsisCharacter }; g.DrawString(Text, Font, b, modRect, stringFormat); } } }
private void pbPDF_MouseEnter(object sender, EventArgs e) { ControlPaint.DrawBorder(pbPDF.CreateGraphics(), pbPDF.ClientRectangle, Color.Orange, ButtonBorderStyle.Inset); }
private void Form1_Paint(object sender, PaintEventArgs e) { ControlPaint.DrawBorder(e.Graphics, ClientRectangle, Color.Blue, ButtonBorderStyle.Solid); }
private void AdminMenu_Paint(object sender, PaintEventArgs e) { ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle, Color.Black, ButtonBorderStyle.Solid); }
protected override void OnPaint(PaintEventArgs e) { Rectangle innerRectangle; int borderOffset = GetBorderOffset(); if (borderOffset != 0) { // 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; } // clip the background so we don't overwrite the border innerRectangle = Rectangle.Inflate(ClientRectangle, -borderOffset, -borderOffset); e.Graphics.SetClip(innerRectangle); } else { innerRectangle = ClientRectangle; } // draw the background if (_texture != null && ShowGrid) { e.Graphics.FillRectangle(_texture, innerRectangle); } else { using (SolidBrush brush = new SolidBrush(BackColor)) e.Graphics.FillRectangle(brush, innerRectangle); } // draw the image if (Image != null) { int left = Padding.Left + borderOffset; int top = Padding.Top + borderOffset; if (AutoScroll) { left += AutoScrollPosition.X; top += AutoScrollPosition.Y; } e.Graphics.DrawImageUnscaled(Image, new Point(left, top)); } // reset the clipping if (borderOffset != 0) { e.Graphics.ResetClip(); } }
private void RenderTab(System.Drawing.Graphics g, int index) { var rect = GetTabRect(index); var closeRect = GetCloseRect(index); var selected = SelectedIndex == index; var tab = TabPages[index]; var points = new[] { new Point(rect.Left, rect.Bottom), new Point(rect.Left, rect.Top + 3), new Point(rect.Left + 3, rect.Top), new Point(rect.Right - 3, rect.Top), new Point(rect.Right, rect.Top + 3), new Point(rect.Right, rect.Bottom), new Point(rect.Left, rect.Bottom) }; // Background var p = PointToClient(MousePosition); var hoverClose = closeRect.Contains(p); var hover = rect.Contains(p); var backColour = tab.BackColor; if (selected) { backColour = ControlPaint.Light(backColour, 1); } else if (hover) { backColour = ControlPaint.Light(backColour, 0.8f); } using (var b = new SolidBrush(backColour)) { g.FillPolygon(b, points); } // Border g.SmoothingMode = SmoothingMode.AntiAlias; g.DrawPolygon(SystemPens.ControlDark, points); if (selected) { using (var pen = new Pen(tab.BackColor)) { g.DrawLine(pen, rect.Left, rect.Bottom, rect.Right, rect.Bottom); } } // Text var textWidth = (int)g.MeasureString(tab.Text, Font).Width; var textLeft = rect.X + 14; var textRight = rect.Right - 26; var textRect = new Rectangle(textLeft + (textRight - textLeft - textWidth) / 2, rect.Y + 4, rect.Width - 26, rect.Height - 5); using (var b = new SolidBrush(tab.ForeColor)) { g.DrawString(tab.Text, Font, b, textRect); } // Close icon using (var pen = new Pen(tab.ForeColor)) { if (hoverClose) { g.DrawRectangle(pen, closeRect.Left + 1, closeRect.Top + 1, closeRect.Width - 2, closeRect.Height - 2); } const int padding = 5; g.DrawLine(pen, closeRect.Left + padding, closeRect.Top + padding, closeRect.Right - padding, closeRect.Bottom - padding); g.DrawLine(pen, closeRect.Right - padding, closeRect.Top + padding, closeRect.Left + padding, closeRect.Bottom - padding); } }
private void DrawThumbnailPlaceholder(Graphics _gfx) { ControlPaint.DrawBorder3D(_gfx, 0, 0, this.Size.Width, this.Size.Height); }
protected override void OnPaint(PaintEventArgs e) { Color backColor, foreColor; MetroThemeStyle _Theme = Theme; MetroColorStyle _Style = Style; if (Parent != null) { if (Parent is IMetroForm) { _Theme = ((IMetroForm)Parent).Theme; _Style = ((IMetroForm)Parent).Style; foreColor = MetroPaint.ForeColor.Button.Press(_Theme); backColor = MetroPaint.GetStyleColor(_Style); } else if (Parent is IMetroControl) { _Theme = ((IMetroControl)Parent).Theme; _Style = ((IMetroControl)Parent).Style; foreColor = MetroPaint.ForeColor.Button.Press(_Theme); backColor = MetroPaint.GetStyleColor(_Style); } else { foreColor = MetroPaint.ForeColor.Button.Press(_Theme); backColor = MetroPaint.GetStyleColor(_Style); } } else { foreColor = MetroPaint.ForeColor.Button.Press(_Theme); backColor = MetroPaint.BackColor.Form(_Theme); } if (isHovered && !isPressed && Enabled) { int _r = backColor.R; int _g = backColor.G; int _b = backColor.B; backColor = ControlPaint.Light(backColor, 0.25f); } else if (isHovered && isPressed && Enabled) { foreColor = MetroPaint.ForeColor.Button.Press(_Theme); backColor = MetroPaint.GetStyleColor(_Style); } else if (!Enabled) { foreColor = MetroPaint.ForeColor.Button.Disabled(_Theme); backColor = MetroPaint.BackColor.Button.Disabled(_Theme); } else { foreColor = MetroPaint.ForeColor.Button.Press(_Theme); } e.Graphics.Clear(backColor); Font buttonFont = MetroFonts.Button(MetroButtonSize.Small, MetroButtonWeight.Bold); TextRenderer.DrawText(e.Graphics, Text, buttonFont, ClientRectangle, foreColor, backColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis); DrawIcon(e.Graphics); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Draws the button in the cell. /// </summary> /// ------------------------------------------------------------------------------------ private void DrawButton(Graphics g, Rectangle rcbtn, int rowIndex) { if (!InternalShowButton(rowIndex)) { return; } bool paintComboButton = (OwningButtonColumn == null ? false : OwningButtonColumn.UseComboButtonStyle); VisualStyleElement element = (paintComboButton ? GetVisualStyleComboButton() : GetVisualStylePushButton()); if (PaintingHelper.CanPaintVisualStyle(element)) { VisualStyleRenderer renderer = new VisualStyleRenderer(element); if (!OwningButtonColumn.DrawDefaultComboButtonWidth) { renderer.DrawBackground(g, rcbtn); } else { Rectangle rc = rcbtn; Size sz = renderer.GetPartSize(g, rc, ThemeSizeType.True); rc.Width = sz.Width + 2; rc.X = (rcbtn.Right - rc.Width); renderer.DrawBackground(g, rc); } } else { ButtonState state = (m_mouseDownOnButton && m_mouseOverButton && m_enabled ? ButtonState.Pushed : ButtonState.Normal); if (!m_enabled) { state |= ButtonState.Inactive; } if (paintComboButton) { ControlPaint.DrawComboButton(g, rcbtn, state); } else { ControlPaint.DrawButton(g, rcbtn, state); } } string buttonText = (OwningButtonColumn == null ? null : OwningButtonColumn.ButtonText); if (string.IsNullOrEmpty(buttonText)) { return; } Font buttonFont = (OwningButtonColumn == null ? SystemInformation.MenuFont : OwningButtonColumn.ButtonFont); // Draw text TextFormatFlags flags = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine | TextFormatFlags.NoPrefix | TextFormatFlags.EndEllipsis | TextFormatFlags.NoPadding | TextFormatFlags.PreserveGraphicsClipping; Color clrText = (m_enabled ? SystemColors.ControlText : SystemColors.GrayText); TextRenderer.DrawText(g, buttonText, buttonFont, rcbtn, clrText, flags); }
private void PaintThemedButtonBackground(PaintEventArgs e, Rectangle bounds, bool up) { PushButtonState pbState = DetermineState(up); // First handle transparent case if (ButtonRenderer.IsBackgroundPartiallyTransparent(pbState)) { ButtonRenderer.DrawParentBackground(e.Graphics, bounds, Control); } // Now draw the actual themed background if (!DpiHelper.IsScalingRequirementMet) { ButtonRenderer.DrawButton(e.Graphics, Control.ClientRectangle, false, pbState); } else { ButtonRenderer.DrawButtonForHandle(e.Graphics, Control.ClientRectangle, false, pbState, Control.HandleInternal); } // 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 painted = false; bool isHighContrastHighlighted = up && IsHighContrastHighlighted(); Color color = isHighContrastHighlighted ? SystemColors.Highlight : Control.BackColor; // Note: PaintEvent.HDC == 0 if GDI+ has used the HDC -- it wouldn't be safe for us // to use it without enough bookkeeping to negate any performance gain of using GDI. if (color.A == 255 && e.HDC != IntPtr.Zero) { if (DisplayInformation.BitsPerPixel > 8) { var r = new RECT(bounds.X, bounds.Y, bounds.Right, bounds.Bottom); // SysColorBrush does not have to be deleted. User32.FillRect( new HandleRef(e, e.HDC), ref r, new HandleRef(this, isHighContrastHighlighted ? User32.GetSysColorBrush(ColorTranslator.ToOle(color) & 0xFF) : Control.BackColorBrush)); painted = true; } } if (!painted) { // don't paint anything from 100% transparent background // if (color.A > 0) { if (color.A == 255) { color = e.Graphics.GetNearestColor(color); } // Color has some transparency or we have no HDC, so we must // fall back to using GDI+. // using (Brush brush = new SolidBrush(color)) { e.Graphics.FillRectangle(brush, bounds); } } } } //This code is mostly taken from the non-themed rendering code path. if (Control.BackgroundImage != null && !DisplayInformation.HighContrast) { ControlPaint.DrawBackgroundImage(e.Graphics, Control.BackgroundImage, Color.Transparent, Control.BackgroundImageLayout, Control.ClientRectangle, bounds, Control.DisplayRectangle.Location, Control.RightToLeft); } }
private void DrawBars(Graphics graph) { SolidBrush brsFont = null; Font valFont = null; StringFormat sfFormat = null; try { brsFont = new SolidBrush(_fontColor); valFont = new Font(_fontFamily, _labelFontSize); sfFormat = new StringFormat(); sfFormat.Alignment = StringAlignment.Center; int i = 0; PointF[] linePoints = null; if (_renderMode == BarGraphRenderMode.Lines) { linePoints = new PointF[DataPoints.Count]; } int pointIndex = 0; // Draw bars and the value above each bar using (Pen pen = new Pen(_fontColor, 0.15f)) { using (SolidBrush whiteBrsh = new SolidBrush(Color.FromArgb(128, Color.White))) { foreach (DataItem item in DataPoints) { using (SolidBrush barBrush = new SolidBrush(item.ItemColor)) { float itemY = _yOrigin + _graphHeight - item.SweepSize; if (_renderMode == BarGraphRenderMode.Lines) { linePoints[pointIndex++] = new PointF(_xOrigin + item.StartPos + (_barWidth / 2), itemY); } else if (_renderMode == BarGraphRenderMode.Bars) { float ox = _xOrigin + item.StartPos; float oy = itemY; float ow = _barWidth; float oh = item.SweepSize; float of = 9.5f; PointF[] pts = new PointF[] { new PointF(ox, oy), new PointF(ox + ow, oy), new PointF(ox + of, oy + of), new PointF(ox + of + ow, oy + of), new PointF(ox, oy + oh), new PointF(ox + of, oy + of + oh), new PointF(ox + of + ow, oy + of + oh) }; graph.FillPolygon(barBrush, new PointF[] { pts[2], pts[3], pts[6], pts[5] }); using (SolidBrush ltBrsh = new SolidBrush(ControlPaint.Light(item.ItemColor, 0.1f))) graph.FillPolygon(ltBrsh, new PointF[] { pts[0], pts[2], pts[5], pts[4] }); using (SolidBrush drkBrush = new SolidBrush(ControlPaint.Dark(item.ItemColor, 0.05f))) graph.FillPolygon(drkBrush, new PointF[] { pts[0], pts[1], pts[3], pts[2] }); graph.DrawLine(pen, pts[0], pts[1]); graph.DrawLine(pen, pts[0], pts[2]); graph.DrawLine(pen, pts[1], pts[3]); graph.DrawLine(pen, pts[2], pts[3]); graph.DrawLine(pen, pts[2], pts[5]); graph.DrawLine(pen, pts[0], pts[4]); graph.DrawLine(pen, pts[4], pts[5]); graph.DrawLine(pen, pts[5], pts[6]); graph.DrawLine(pen, pts[3], pts[6]); // Draw data value if (_displayBarData && (i % _interval) == 0) { float sectionWidth = (_barWidth + _spaceBtwBars); float startX = _xOrigin + (i * sectionWidth) + (sectionWidth / 2); // This draws the value on center of the bar float startY = itemY - 2f - valFont.Height; // Positioned on top of each bar by 2 pixels RectangleF recVal = new RectangleF(startX - ((sectionWidth * _interval) / 2), startY, sectionWidth * _interval, valFont.Height); SizeF sz = graph.MeasureString(item.Value.ToString("#,###.##"), valFont, recVal.Size, sfFormat); //using ( SolidBrush brsh = new SolidBrush( Color.FromArgb( 180, 255, 255, 255 ) ) ) // graph.FillRectangle( brsh, new RectangleF(recVal.X+((recVal.Width-sz.Width)/2),recVal.Y+((recVal.Height-sz.Height)/2),sz.Width+4,sz.Height) ); //graph.DrawString(item.Value.ToString("#,###.##"), valFont, brsFont, recVal, sfFormat); for (int box = -1; box <= 1; ++box) { for (int boy = -1; boy <= 1; ++boy) { if (box == 0 && boy == 0) { continue; } RectangleF rco = new RectangleF(recVal.X + box, recVal.Y + boy, recVal.Width, recVal.Height); graph.DrawString(item.Value.ToString("#,###.##"), valFont, whiteBrsh, rco, sfFormat); } } graph.DrawString(item.Value.ToString("#,###.##"), valFont, brsFont, recVal, sfFormat); } } i++; } } if (_renderMode == BarGraphRenderMode.Lines) { if (linePoints.Length >= 2) { using (Pen linePen = new Pen(Color.FromArgb(220, Color.Red), 2.5f)) graph.DrawCurve(linePen, linePoints, 0.5f); } using (Pen linePen = new Pen(Color.FromArgb(40, _fontColor), 0.8f)) { for (int j = 0; j < linePoints.Length; ++j) { graph.DrawLine(linePen, linePoints[j], new PointF(linePoints[j].X, _yOrigin + _graphHeight)); DataItem item = DataPoints[j]; float itemY = _yOrigin + _graphHeight - item.SweepSize; // Draw data value if (_displayBarData && (j % _interval) == 0) { graph.FillEllipse(brsFont, new RectangleF(linePoints[j].X - 2.0f, linePoints[j].Y - 2.0f, 4.0f, 4.0f)); float sectionWidth = (_barWidth + _spaceBtwBars); float startX = _xOrigin + (j * sectionWidth) + (sectionWidth / 2); // This draws the value on center of the bar float startY = itemY - 2f - valFont.Height; // Positioned on top of each bar by 2 pixels RectangleF recVal = new RectangleF(startX - ((sectionWidth * _interval) / 2), startY, sectionWidth * _interval, valFont.Height); SizeF sz = graph.MeasureString(item.Value.ToString("#,###.##"), valFont, recVal.Size, sfFormat); //using ( SolidBrush brsh = new SolidBrush( Color.FromArgb( 48, 255, 255, 255 ) ) ) // graph.FillRectangle( brsh, new RectangleF(recVal.X+((recVal.Width-sz.Width)/2),recVal.Y+((recVal.Height-sz.Height)/2),sz.Width+4,sz.Height) ); for (int box = -1; box <= 1; ++box) { for (int boy = -1; boy <= 1; ++boy) { if (box == 0 && boy == 0) { continue; } RectangleF rco = new RectangleF(recVal.X + box, recVal.Y + boy, recVal.Width, recVal.Height); graph.DrawString(item.Value.ToString("#,###.##"), valFont, whiteBrsh, rco, sfFormat); } } graph.DrawString(item.Value.ToString("#,###.##"), valFont, brsFont, recVal, sfFormat); } } } } } } } finally { if (brsFont != null) { brsFont.Dispose(); } if (valFont != null) { valFont.Dispose(); } if (sfFormat != null) { sfFormat.Dispose(); } } }
private void panelMain_Paint(object sender, PaintEventArgs e) { ControlPaint.DrawBorder(e.Graphics, this.panelMain.ClientRectangle, Color.White, ButtonBorderStyle.Solid); }
protected virtual void OnPaintForeground(PaintEventArgs e) { Color borderColor, foreColor; if (isHovered && !isPressed && Enabled) { borderColor = MetroPaint.BorderColor.Button.Hover(Theme); foreColor = MetroPaint.ForeColor.Button.Hover(Theme); } else if (isHovered && isPressed && Enabled) { borderColor = MetroPaint.BorderColor.Button.Press(Theme); foreColor = MetroPaint.ForeColor.Button.Press(Theme); } else if (!Enabled) { borderColor = MetroPaint.BorderColor.Button.Disabled(Theme); foreColor = MetroPaint.ForeColor.Button.Disabled(Theme); } else { borderColor = MetroPaint.BorderColor.Button.Normal(Theme); if (useCustomForeColor) { foreColor = ForeColor; } else if (Highlight) { foreColor = MetroPaint.BackColor.Form(Theme); } else if (useStyleColors) { foreColor = MetroPaint.GetStyleColor(Style); } else { foreColor = MetroPaint.ForeColor.Button.Normal(Theme); } } /*using (Pen p = new Pen(borderColor)) * { * Rectangle borderRect = new Rectangle(0, 0, Width - 1, Height - 1); * e.Graphics.DrawRectangle(p, borderRect); * } * * if (Highlight && !isHovered && !isPressed && Enabled) * { * using (Pen p = MetroPaint.GetStylePen(Style)) * { * Rectangle borderRect = new Rectangle(0, 0, Width - 1, Height - 1); * e.Graphics.DrawRectangle(p, borderRect); * borderRect = new Rectangle(1, 1, Width - 3, Height - 3); * e.Graphics.DrawRectangle(p, borderRect); * } * }*/ TextRenderer.DrawText(e.Graphics, Text, MetroFonts.Button(metroButtonSize, metroButtonWeight), ClientRectangle, foreColor, MetroPaint.GetTextFormatFlags(TextAlign)); OnCustomPaintForeground(new MetroPaintEventArgs(Color.Empty, foreColor, e.Graphics)); if (displayFocusRectangle && isFocused) { ControlPaint.DrawFocusRectangle(e.Graphics, ClientRectangle); } }
protected override void OnPaint(PaintEventArgs e) { Rectangle borderRect = new Rectangle(new Point(BUTTON.Location.X, BUTTON.Location.Y), BUTTON.Size); ControlPaint.DrawBorder(e.Graphics, borderRect, SystemColors.ActiveBorder, ButtonBorderStyle.Solid); }
//<snippet2> // This method draws a focus rectangle on Button2 using the // handle and client rectangle of Button2. private void Button1_Click(System.Object sender, System.EventArgs e) { ControlPaint.DrawFocusRectangle(Graphics.FromHwnd(Button2.Handle), Button2.ClientRectangle); }
void m_Combo_DrawItem(object sender, DrawItemEventArgs e) { int iconWidth = SystemInformation.SmallIconSize.Width; int indent = ((e.State & DrawItemState.ComboBoxEdit) == 0) ? (iconWidth / 2) : 0; if (e.Index != -1) { string display; ComboItem item = (ComboItem)m_Combo.Items[e.Index]; Color textColor = SystemColors.WindowText; Rectangle textRect; int textOffset; SizeF size; if ((e.State & DrawItemState.ComboBoxEdit) != 0) { // Don't draw the folder location in the edit box when // the control is Editable as the edit control will // take care of that. display = m_Editable ? string.Empty : GetEditString(); } else { display = item.Folder.DisplayName; } size = TextRenderer.MeasureText(display, m_Combo.Font); textRect = new Rectangle(e.Bounds.Left + iconWidth + (item.Indent * indent) + 3, e.Bounds.Y, (int)size.Width, e.Bounds.Height); textOffset = (int)((e.Bounds.Height - size.Height) / 2); // If the text is being drawin in the main combo box edit area, // draw the text 1 pixel higher - this is how it looks in Windows. if ((e.State & DrawItemState.ComboBoxEdit) != 0) { textOffset -= 1; } if ((e.State & DrawItemState.Selected) != 0) { e.Graphics.FillRectangle(SystemBrushes.Highlight, textRect); textColor = SystemColors.HighlightText; } else { e.DrawBackground(); } if ((e.State & DrawItemState.Focus) != 0) { ControlPaint.DrawFocusRectangle(e.Graphics, textRect); } SystemImageList.DrawSmallImage( e.Graphics, new Point(e.Bounds.Left + (item.Indent * indent), e.Bounds.Top), item.Folder.GetSystemImageListIndex(ShellIconType.SmallIcon, ShellIconFlags.OverlayIndex), (e.State & DrawItemState.Selected) != 0 ); TextRenderer.DrawText(e.Graphics, display, m_Combo.Font, new Point(textRect.Left, textRect.Top + textOffset), textColor); } }
// 填充全部内容 int Fill(LibraryChannel channel_param, TreeNode node, out string strError) { strError = ""; TreeNodeCollection children = null; if (node == null) { children = this.Nodes; } else { children = node.Nodes; } if (string.IsNullOrEmpty(this.Lang)) { this.Lang = "zh"; } LibraryChannel channel = null; TimeSpan old_timeout = new TimeSpan(0); if (channel_param != null) { channel = channel_param; } else { channel = this.CallGetChannel(true); old_timeout = channel.Timeout; channel.Timeout = new TimeSpan(0, 5, 0); } bool restoreLoading = IsLoading(node); try { string start_path = GetNodePath(node); { DirItemLoader loader = new DirItemLoader(channel, null, start_path, "", this.Lang); children.Clear(); foreach (ResInfoItem item in loader) { TreeNode nodeNew = new TreeNode(item.Name, item.Type, item.Type); nodeNew.Tag = item; if (item.HasChildren) { SetLoading(nodeNew); } if (EnabledIndices != null && StringUtil.IsInList(nodeNew.ImageIndex, EnabledIndices) == false) { nodeNew.ForeColor = ControlPaint.LightLight(nodeNew.ForeColor); } if (HideIndices != null && StringUtil.IsInList(nodeNew.ImageIndex, HideIndices) == true) { continue; } children.Add(nodeNew); } } // 在根级追加 '!' 下的 dp2library 本地文件或目录 if (string.IsNullOrEmpty(start_path)) { ResInfoItem item = new ResInfoItem(); item.Name = "!"; item.Type = 4; item.HasChildren = true; TreeNode nodeNew = new TreeNode(item.Name, item.Type, item.Type); nodeNew.Tag = item; if (item.HasChildren) { SetLoading(nodeNew); } if (EnabledIndices != null && StringUtil.IsInList(nodeNew.ImageIndex, EnabledIndices) == false) { nodeNew.ForeColor = ControlPaint.LightLight(nodeNew.ForeColor); } if (HideIndices != null && StringUtil.IsInList(nodeNew.ImageIndex, HideIndices) == true) { } else { children.Add(nodeNew); } } restoreLoading = false; // 防止 finally 复原 return(0); } catch (ChannelException ex) { strError = ex.Message; return(-1); #if NO if (ex.ErrorCode == ErrorCode.AccessDenied) { strError = ex.Message; return(-1); } strError = "Fill() 过程出现异常: " + ExceptionUtil.GetExceptionText(ex); return(-1); #endif } catch (Exception ex) { strError = "Fill() 过程出现异常: " + ExceptionUtil.GetExceptionText(ex); return(-1); } finally { if (channel_param == null) { channel.Timeout = old_timeout; this.CallReturnChannel(channel, true); } if (restoreLoading) { SetLoading(node); if (node != null) { node.Collapse(); } } } }