public SetBlendTriangularShape ( float focus ) : void | ||
focus | float | |
return | void |
/// <summary> Method is called whenever this form is resized. </summary> /// <param name="e"></param> /// <remarks> This redraws the background of this form </remarks> protected override void OnResize(EventArgs e) { base.OnResize(e); // Get rid of any current background image if (BackgroundImage != null) { BackgroundImage.Dispose(); BackgroundImage = null; } if (ClientSize.Width > 0) { // Create the items needed to draw the background Bitmap image = new Bitmap(ClientSize.Width, ClientSize.Height); Graphics gr = Graphics.FromImage(image); Rectangle rect = new Rectangle(new Point(0, 0), ClientSize); // Create the brush LinearGradientBrush brush = new LinearGradientBrush(rect, SystemColors.Control, ControlPaint.Dark(SystemColors.Control), LinearGradientMode.Vertical); brush.SetBlendTriangularShape(0.33F); // Create the image gr.FillRectangle(brush, rect); gr.Dispose(); // Set this as the backgroundf BackgroundImage = image; } }
private void DrawSector(Graphics g, PointF center, PointF p1, PointF p2, Color innerColor, Color outerColor) { GraphicsPath pt = new GraphicsPath(); pt.AddLine(p1, center); pt.AddLine(center, p2); LinearGradientBrush lgb = new LinearGradientBrush( GetVertical(center, p1, p2) , center, outerColor, innerColor ); if (_triangularShape) lgb.SetBlendTriangularShape(0.5f); g.FillPath( lgb, pt ); }
private void DrawSector(Graphics g, PointF center, PointF p1, PointF p2, Color innerColor, Color outerColor) { GraphicsPath pt = new GraphicsPath(); pt.AddLine(p1, center); pt.AddLine(center, p2); LinearGradientBrush lgb = new LinearGradientBrush(GetVertical(center, p1, p2), center, outerColor, innerColor); if (_triangularShape) { lgb.SetBlendTriangularShape(0.5f); } g.FillPath(lgb, pt); }
private void PraysTimes_Paint(object sender, PaintEventArgs e) { using (GraphicsPath Path = new GraphicsPath()) { using (LinearGradientBrush lgb = new LinearGradientBrush(ClientRectangle, Properties.Settings.Default.panelMoveColorLight, Properties.Settings.Default.panelMoveColorDark, 90, true)) { lgb.SetBlendTriangularShape(0.5f); Path.AddArc(0, 0, 30, 30, 180, 90); Path.AddArc(this.ClientRectangle.Width - 30, 0, 30, 30, 270, 90); Path.AddArc(this.ClientRectangle.Width - 30, this.ClientRectangle.Height - 30, 30, 30, 360, 90); Path.AddArc(0, this.ClientRectangle.Height - 30, 30, 30, 90, 90); this.Region = new Region(Path); e.Graphics.FillRegion(lgb, this.Region); } } }
public void SetBlendTriangularShape_Scale () { LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f); // max valid lgb.SetBlendTriangularShape (0, 1); Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1"); // min valid lgb.SetBlendTriangularShape (1, 0); Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1"); // middle lgb.SetBlendTriangularShape (0.5f, 0.5f); Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1"); // no impact on matrix }
public void Rectangle () { LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f); CheckDefaultRectangle ("Original", lgb.Rectangle); lgb.MultiplyTransform (new Matrix (2, 0, 0, 2, 2, 2)); CheckDefaultRectangle ("Multiply", lgb.Rectangle); lgb.ResetTransform (); CheckDefaultRectangle ("Reset", lgb.Rectangle); lgb.RotateTransform (90); CheckDefaultRectangle ("Rotate", lgb.Rectangle); lgb.ScaleTransform (4, 0.25f); CheckDefaultRectangle ("Scale", lgb.Rectangle); lgb.TranslateTransform (-10, -20); CheckDefaultRectangle ("Translate", lgb.Rectangle); lgb.SetBlendTriangularShape (0.5f); CheckDefaultRectangle ("SetBlendTriangularShape", lgb.Rectangle); lgb.SetSigmaBellShape (0.5f); CheckDefaultRectangle ("SetSigmaBellShape", lgb.Rectangle); }
private void drawGlassButton(Graphics g, RectangleF bounds, int opacity) { // initial bounds bounds.Inflate(-1, -1); // draw using anti alias using (GraphicsMode mode = new GraphicsMode(g, SmoothingMode.AntiAlias)) { // draw the border around the button using (GraphicsPath buttonPath = createRoundRectanglePath( g, bounds.X, bounds.Y, bounds.Width, bounds.Height, 1f)) { using (LinearGradientBrush borderBrush = new LinearGradientBrush( bounds, Color.FromArgb(opacity * 20, ButtonGradientEnd), Color.FromArgb(opacity * 20, ButtonGradientBegin), 90f)) { borderBrush.SetSigmaBellShape(0.5f); using (Pen borderPen = new Pen(borderBrush, .5f)) g.DrawPath(borderPen, buttonPath); } // create a clipping region RectangleF clipBounds = bounds; clipBounds.Inflate(-1, -1); using (GraphicsPath clipPath = createRoundRectanglePath( g, clipBounds.X, clipBounds.Y, clipBounds.Width, clipBounds.Height, 1f)) { using (Region region = new Region(clipPath)) g.SetClip(region, CombineMode.Exclude); } // fill in the edge accent using (LinearGradientBrush edgeBrush = new LinearGradientBrush( bounds, Color.FromArgb(opacity * 15, ButtonBorderColor), Color.FromArgb(opacity * 5, Color.Black), 90f)) { edgeBrush.SetBlendTriangularShape(0.1f); g.FillPath(edgeBrush, buttonPath); g.ResetClip(); bounds.Inflate(-1, -1); } // fill the button with a subtle glow using (LinearGradientBrush fillBrush = new LinearGradientBrush( bounds, Color.FromArgb(opacity * 10, Color.White), Color.FromArgb(opacity * 5, ButtonGradientBegin), LinearGradientMode.ForwardDiagonal)) { fillBrush.SetBlendTriangularShape(0.4f); g.FillPath(fillBrush, buttonPath); g.ResetClip(); } } } }
private void drawLinearGradient(Rectangle rDmn, IntPtr hdc, LinearGradientMode m) { Graphics g = Graphics.FromHdc(hdc); float o = _fOpacity * 255; Color c1 = Color.FromArgb((int)o, _oGradientStartColor); Color c2 = Color.FromArgb((int)o, _oGradientEndColor); LinearGradientBrush hB = new LinearGradientBrush( rDmn, c1, c2, m); switch (_eGradientStyle) { case GradientStyle.VerticalTube: hB.SetBlendTriangularShape(.5f, 1.0f); g.FillRectangle(hB, rDmn); break; case GradientStyle.HorizontalTube: hB.SetBlendTriangularShape(.5f, 1.0f); g.FillRectangle(hB, rDmn); break; case GradientStyle.SigmaBellShape: hB.SetSigmaBellShape(.5f, 1.0f); g.FillRectangle(hB, rDmn); break; default: g.FillRectangle(hB, rDmn); break; } hB.Dispose(); g.Dispose(); }
void PaintView8(Graphics g) { // Create a LinearGradientBrush. Rectangle myRect = new Rectangle(20, 20, 200, 100); LinearGradientBrush myLGBrush = new LinearGradientBrush( myRect, Color.Blue, Color.Red, 0.0f, true); // Draw an ellipse to the screen using the LinearGradientBrush. g.FillEllipse(myLGBrush, myRect); // Create a triangular shaped brush with the peak at the center // of the drawing area. myLGBrush.SetBlendTriangularShape(.50f, 1.0f); // Use the triangular brush to draw a second ellipse. myRect.Y = 150; g.FillEllipse(myLGBrush, myRect); }
void PaintView13(Graphics g) { // Create a rectangle Rectangle rect = new Rectangle(0, 0, 40, 20); // Create a linear gradient brush LinearGradientBrush rgBrush = new LinearGradientBrush( rect, Color.Black, Color.Blue, 0.0f, true); // Fill rectangle g.FillRectangle(rgBrush, new Rectangle(10, 10, 300, 100)); // Set sigma bell shape rgBrush.SetSigmaBellShape(0.8f, 1.0f); // Fill rectangle again g.FillRectangle(rgBrush, new Rectangle(10, 120, 300, 100)); // Set blend triangular shape rgBrush.SetBlendTriangularShape(0.2f, 1.0f); // Fill rectangle again g.FillRectangle(rgBrush, new Rectangle(10, 240, 300, 100)); }
protected virtual void OnPaint(object sender, PaintEventArgs e) { if (m_Parent.WindowState != FormWindowState.Minimized) { e.Graphics.SmoothingMode = SmoothingMode.HighSpeed; top = new Rectangle(Border_Size, 0, m_Parent.ClientRectangle.Width - (Border_Size * 2), Border_Size); rigt = new Rectangle(m_Parent.ClientRectangle.Width - Border_Size, Border_Size, Border_Size, m_Parent.ClientRectangle.Height - (Border_Size * 2)); bottom = new Rectangle(Border_Size, m_Parent.ClientRectangle.Height - Border_Size, m_Parent.ClientRectangle.Width - (Border_Size * 2), Border_Size); Left_Top = new Rectangle(0, 0, Border_Size, Border_Size); Left_B = new Rectangle(0, m_Parent.ClientRectangle.Height - Border_Size, Border_Size, Border_Size); Panel_move = new Rectangle(Border_Size, Border_Size, m_Parent.ClientRectangle.Width - (Border_Size * 2), Panel_Move_Size); if (controlBox) { DrawCloseButtonNormal(); DrawMaxButtonNormal(); DrawMinButtonNormal(); } Top_R = new Rectangle(m_Parent.ClientRectangle.Width - Border_Size, 0, Border_Size, Border_Size); Right_B = new Rectangle(m_Parent.ClientRectangle.Width - Border_Size, m_Parent.ClientRectangle.Height - Border_Size, Border_Size, Border_Size); left = new Rectangle(0, Border_Size, Border_Size, m_Parent.ClientRectangle.Height - (Border_Size * 2)); LinearGradientBrush lgb_top = new LinearGradientBrush(top, this.Border_Top_light, this.Border_Top_Dark, 90, true); LinearGradientBrush lgb_LR = new LinearGradientBrush(left, this.Border_LR_Dark, this.Border_LR_light, 180, true); LinearGradientBrush lgb_Bottom = new LinearGradientBrush(bottom, this.Border_Bottom_light, this.Border_Bottom_Dark, 90, true); LinearGradientBrush lgb_PanelMov = new LinearGradientBrush(Panel_move, this.Panel_Move_Dark, this.Panel_Move_light, 90, true); lgb_PanelMov.SetBlendTriangularShape(0.5f); lgb_PanelMov.SetSigmaBellShape(0.5f); SizeF m_size = e.Graphics.MeasureString(this.Text, m_Font); SizeF mm_size = e.Graphics.MeasureString(text, mm_font); ico = new Icon(m_Parent.Icon, 16, 16); e.Graphics.FillRectangle(lgb_LR, left); e.Graphics.FillRectangle(lgb_LR, rigt); e.Graphics.FillRectangle(lgb_LR, Left_Top); e.Graphics.FillRectangle(lgb_Bottom, Left_B); e.Graphics.FillRectangle(lgb_LR, Top_R); e.Graphics.FillRectangle(lgb_Bottom, Right_B); e.Graphics.FillRectangle(lgb_PanelMov, Panel_move); e.Graphics.FillRectangle(lgb_Bottom, bottom); e.Graphics.FillRectangle(lgb_top, top); rectClose = new Rectangle(m_Parent.ClientRectangle.Right - (bmp_Close.Width + 6), (Panel_Move_Size + Border_Size - bmp_Close.Height) / 2, bmp_Close.Width, bmp_Close.Height); rectMax = new Rectangle(m_Parent.ClientRectangle.Right - (bmp_Close.Width + 8 + bmp_Max.Width), ((Panel_Move_Size + Border_Size) - bmp_Max.Height) / 2, bmp_Max.Width, bmp_Max.Height); rectMin = new Rectangle(m_Parent.ClientRectangle.Right - (bmp_Close.Width + 10 + bmp_Min.Width * 2), ((Panel_Move_Size + Border_Size) - bmp_Min.Height) / 2, bmp_Min.Width, bmp_Min.Height); iconRec = new Rectangle(Panel_move.X + 2, (Panel_Move_Size - ico.Height + 4) / 2, ico.Width, ico.Height); TitRec = new Rectangle(Panel_move.X + (iconRec.Width + 5 + (int)m_size.Width), Panel_move.Y, Panel_move.Size.Width - (rectMin.Width*14), Panel_move.Height); //e.Graphics.FillRectangle(Brushes.Bisque, TitRec); TextRenderer.DrawText(e.Graphics, this.Text, m_Font, new Rectangle(Panel_move.X + ico.Width ,Panel_move.Y, (int)m_size.Width,(int)m_size.Height), m_TextColor,TextFormatFlags.VerticalCenter); TextRenderer.DrawText(e.Graphics, text, mm_font,TitRec, Color.White, Color.Transparent, textFlags); e.Graphics.DrawIconUnstretched(ico, iconRec); } }
/// <summary> /// Draws the list of wizard steps, with the current step highlighted and any disabled steps grayed out. /// </summary> protected override void OnPaint(PaintEventArgs e) { Bitmap bg = Properties.Resources.wizard_background; int bg_h = (int)(bg.Height * (Width / (float)bg.Width)); //The assumption made is that Width/bg.Width ratio always matches the system's dpi setting. Normally (at 100% dpi setting) this equals to 1. int bg_top = Height - bg_h; if (bg_top > 0) { using (SolidBrush bgBrush = new SolidBrush(bgBrushColor)) e.Graphics.FillRectangle(bgBrush, new Rectangle(0, 0, Width, bg_top)); } int bg_w = Width; //This makes sure we compensate for rounding if it happened while bg_h was calculated. (to avoid gap on the right) //Switch to 125% dpi to see why this is needed... if (Width / (float)bg.Width != 1f) bg_w++; e.Graphics.DrawImage(bg, new Rectangle(0, bg_top, bg_w, bg_h )); using (LinearGradientBrush highlight = new LinearGradientBrush(Point.Empty, new Point(Width, 0), HighlightColorEdge, HighlightColorMiddle)) { highlight.SetBlendTriangularShape(0.5f); float y = 15F; for (int step = 0; step < Steps.Count; step++) { if (step == _currentStep) { e.Graphics.FillRectangle(highlight, 0, y, Width, 20F); TextRenderer.DrawText(e.Graphics, Steps[step].Text, Program.DefaultFontBold, new Rectangle(10, (int)y, Width, 20), SystemColors.HighlightText, TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.HidePrefix); } else { TextRenderer.DrawText(e.Graphics, Steps[step].Text, Program.DefaultFont, new Rectangle(10, (int)y, Width, 20), Steps[step].DisableStep ? SystemColors.GrayText : Color.Black, TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.HidePrefix); } y += 24F; } } }
private void createBufferImage() { ProgressBar pb = (ProgressBar)Control.FromHandle(_hProgressBarWnd); Rectangle bounds = pb.ClientRectangle; Rectangle bdcopy = bounds; _cBufferDc.Height = pb.Height; _cBufferDc.Width = pb.Width; Graphics g = Graphics.FromHdc(_cBufferDc.Hdc); using (GraphicsMode mode = new GraphicsMode(g, SmoothingMode.AntiAlias)) { using (GraphicsPath barPath = createRoundRectanglePath( g, bounds.X, bounds.Y, bounds.Width, bounds.Height, 1f)) { using (SolidBrush backBrush = new SolidBrush(pb.BackColor)) g.FillRectangle(backBrush, bounds); // draw the frame using (LinearGradientBrush borderBrush = new LinearGradientBrush( bounds, Color.DarkGray, Color.Silver, 90f)) { borderBrush.SetSigmaBellShape(0.5f); using (Pen borderPen = new Pen(borderBrush, .5f)) g.DrawPath(borderPen, barPath); } bounds.Width--; bounds.Height--; // create a clipping region RectangleF clipBounds = bounds; clipBounds.Inflate(-1, -1); using (GraphicsPath clipPath = createRoundRectanglePath( g, clipBounds.X, clipBounds.Y, clipBounds.Width + 1, clipBounds.Height + 1, 1f)) { using (Region region = new Region(clipPath)) g.SetClip(region, CombineMode.Exclude); } // fill in the edge accent using (LinearGradientBrush edgeBrush = new LinearGradientBrush( bounds, Color.DarkGray, Color.Black, 90f)) { edgeBrush.SetBlendTriangularShape(0.5f); g.FillPath(edgeBrush, barPath); g.ResetClip(); bounds.Inflate(-1, -1); } // fill with a subtle glow using (LinearGradientBrush fillBrush = new LinearGradientBrush( bounds, Color.FromArgb(100, Color.White), Color.FromArgb(100, Color.Silver), LinearGradientMode.Vertical)) { fillBrush.SetBlendTriangularShape(0.4f); g.FillPath(fillBrush, barPath); g.ResetClip(); } } } g.Dispose(); }
private void drawCombo(ToolStripComboBox combo, bool focused) { Rectangle bounds; Rectangle clientBounds = combo.ComboBox.ClientRectangle; clientBounds.Height--; if (combo.DroppedDown) focused = true; if (combo.IsOnOverflow) { //bounds.X = 2; } if (combo.RightToLeft == RightToLeft.Yes) bounds = new Rectangle(new Point(0, 0), new Size(14, combo.Height)); else bounds = new Rectangle(new Point(combo.Width - 14, 0), new Size(14, combo.Height)); using (Graphics g = Graphics.FromHwnd(combo.ComboBox.Handle)) { // prepaint entire background Rectangle flatRect = clientBounds; if (combo.RightToLeft == RightToLeft.Yes) flatRect.X += 14; else flatRect.Width -= 14; flatRect.Inflate(-1, -1); flatRect.Height++; using (Brush flatBrush = new SolidBrush(Color.White)) g.FillRectangle(flatBrush, flatRect); if (Parent.ToolStripStyle == ToolStripType.FlatColor) { // fill the background using (Brush flatBrush = new SolidBrush(Parent.ButtonGradientBegin)) g.FillRectangle(flatBrush, bounds); // draw a focused mask if (focused) { bounds.Inflate(0, -1); using (Brush flatBrush = new SolidBrush(Color.FromArgb(100, Color.White))) g.FillRectangle(flatBrush, bounds); bounds.Inflate(0, 1); } // frame the button using (Pen framePen = new Pen(Color.FromArgb(100, Parent.SeperatorOuterColor), 0.5f)) g.DrawRectangle(framePen, clientBounds); bounds.Width--; // draw a border using (Pen borderPen = new Pen(Color.FromArgb(200, Parent.SeperatorOuterColor), 0.5f)) g.DrawRectangle(borderPen, bounds); } else if (Parent.ToolStripStyle == ToolStripType.Image) { // blit the image in if (ToolStrip.BackgroundImage != null) { g.DrawImage(ToolStrip.BackgroundImage, bounds, bounds, GraphicsUnit.Pixel); } if (focused) { // fill in the edge accent using (LinearGradientBrush fillBrush = new LinearGradientBrush(bounds, Color.FromArgb(50, Parent.SeperatorInnerColor), Color.FromArgb(50, Parent.SeperatorOuterColor), 90f)) { fillBrush.SetBlendTriangularShape(0.2f); g.FillRectangle(fillBrush, bounds); } } // draw the frame using (Pen framePen = new Pen(Color.FromArgb(150, Color.Black), 0.5f)) g.DrawRectangle(framePen, clientBounds); bounds.Width--; using (Pen borderPen = new Pen(Color.FromArgb(200, Color.Black), 0.5f)) g.DrawRectangle(borderPen, bounds); } else { // fill in the edge accent using (LinearGradientBrush fillBrush = new LinearGradientBrush(bounds, Parent.ToolStripGradientBegin, Parent.ToolStripGradientEnd, Parent.gradientDirection(_toolStrip, Parent.ToolStripGradientDirection))) { fillBrush.Blend = Parent.ToolStripGradientBlend; g.FillRectangle(fillBrush, bounds); } // draw a focused mask if (focused) { // fill in the mask using (LinearGradientBrush fillBrush = new LinearGradientBrush(bounds, Color.FromArgb(50, Color.LightGray), Color.FromArgb(50, Color.White), 90f)) { fillBrush.SetBlendTriangularShape(0.2f); g.FillRectangle(fillBrush, bounds); } } using (Pen framePen = new Pen(Color.FromArgb(150, Color.Black), 0.5f)) g.DrawRectangle(framePen, clientBounds); bounds.Width--; using (Pen borderPen = new Pen(Color.FromArgb(200, Color.Black), 0.5f)) g.DrawRectangle(borderPen, bounds); } drawComboArrow(g, bounds); } }
/// <summary> /// Draws the list of wizard steps, with the current step highlighted and any disabled steps grayed out. /// </summary> protected override void OnPaint(PaintEventArgs e) { Bitmap bg = Properties.Resources.wizard_background; int bg_h = bg.Height; int bg_top = Height - bg_h; if (bg_top > 0) e.Graphics.FillRectangle(bgBrush, new Rectangle(0, 0, Width, bg_top)); e.Graphics.DrawImage(bg, new Rectangle(0, bg_top, bg.Width, bg_h)); using (LinearGradientBrush highlight = new LinearGradientBrush(Point.Empty, new Point(Width, 0), HighlightColorEdge, HighlightColorMiddle)) { highlight.SetBlendTriangularShape(0.5f); float y = 15F; for (int step = 0; step < Steps.Count; step++) { if (step == _currentStep) { e.Graphics.FillRectangle(highlight, 0, y, Width, 20F); TextRenderer.DrawText(e.Graphics, Steps[step].Text, Program.DefaultFontBold, new Rectangle(10, (int)y, Width, 20), SystemColors.HighlightText, TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.HidePrefix); } else { TextRenderer.DrawText(e.Graphics, Steps[step].Text, Program.DefaultFont, new Rectangle(10, (int)y, Width, 20), Steps[step].DisableStep ? SystemColors.GrayText : Color.Black, TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.HidePrefix); } y += 24F; } } }
protected override void OnDrawItem(DrawItemEventArgs e) { Graphics grfx = e.Graphics; Rectangle rectColor = new Rectangle(e.Bounds.Left, e.Bounds.Top, 2 * e.Bounds.Height, e.Bounds.Height); rectColor.Inflate(-1, -1); Rectangle rectText = new Rectangle(e.Bounds.Left + 2 * e.Bounds.Height, e.Bounds.Top, e.Bounds.Width - 2 * e.Bounds.Height, e.Bounds.Height); if (this.Enabled) e.DrawBackground(); float item = (float)Items[e.Index]; using (LinearGradientBrush br = new LinearGradientBrush(rectColor, e.ForeColor, e.BackColor, LinearGradientMode.Horizontal)) { br.SetBlendTriangularShape(item); grfx.FillRectangle(br, rectColor); } using (SolidBrush foreColorBrush = new SolidBrush(e.ForeColor)) { string text = Altaxo.Serialization.GUIConversion.ToString(item); grfx.DrawString(text, Font, foreColorBrush, rectText); } }
private void drawPhaseBar(int y, IntPtr hdc) { Rectangle rDmn = new Rectangle(2, y, _cFaderDc.Width - 4, 12); Graphics g = Graphics.FromHdc(hdc); Color c1 = Color.FromArgb(60, Color.Snow); Color c2 = Color.FromArgb(60, Color.WhiteSmoke); LinearGradientBrush hB = new LinearGradientBrush( rDmn, c1, c2, LinearGradientMode.Vertical); // magnifier effect alphaBlit(hdc, 2, y, _cFaderDc.Width - 4, 12, _cFaderDc.Hdc, 2, y, _cFaderDc.Width - 4, 14, 220); hB.SetBlendTriangularShape(.5f, 1.0f); g.FillRectangle(hB, rDmn); hB.Dispose(); g.Dispose(); }
/// <summary> /// Paints the content of the cell /// </summary> protected override void Paint(Graphics g, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { int leftMargin = STANDARD_HORIZONTAL_MARGIN; int rightMargin = STANDARD_HORIZONTAL_MARGIN; int topMargin = STANDARD_VERTICAL_MARGIN; int bottomMargin = STANDARD_VERTICAL_MARGIN; int imgHeight = 1; int imgWidth = 1; int progressWidth = 1; PointF fontPlacement = new PointF(0, 0); int progressVal; if (value != null) //progressVal = (int)value; progressVal = (int)((double)value); else progressVal = 0; // Draws the cell grid base.Paint(g, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, (paintParts & ~DataGridViewPaintParts.ContentForeground)); // Get margins from the style if (null != cellStyle) { leftMargin = cellStyle.Padding.Left; rightMargin = cellStyle.Padding.Right; topMargin = cellStyle.Padding.Top; bottomMargin = cellStyle.Padding.Bottom; } // Calculate the sizes imgHeight = cellBounds.Bottom - cellBounds.Top - (topMargin + bottomMargin); imgWidth = cellBounds.Right - cellBounds.Left - (leftMargin + rightMargin); if (imgWidth <= 0) { imgWidth = 1; } if (imgHeight <= 0) { imgHeight = 1; } // Calculate the progress progressWidth = (imgWidth * (progressVal) / 100); if (progressWidth <= 0) { if (progressVal > 0) { progressWidth = 1; } else { progressWidth = 0; } } // Calculate the font if (null != formattedValue) { SizeF availArea = new SizeF(imgWidth, imgHeight); SizeF fontSize = g.MeasureString(formattedValue.ToString(), cellStyle.Font, availArea); #region [Font Placement Calc] if (null == cellStyle) { fontPlacement.Y = cellBounds.Y + topMargin + (((float)imgHeight - fontSize.Height) / 2); fontPlacement.X = cellBounds.X + leftMargin + (((float)imgWidth - fontSize.Width) / 2); } else { // Set the Y vertical position switch (cellStyle.Alignment) { case DataGridViewContentAlignment.BottomCenter: case DataGridViewContentAlignment.BottomLeft: case DataGridViewContentAlignment.BottomRight: { fontPlacement.Y = cellBounds.Y + topMargin + imgHeight - fontSize.Height; break; } case DataGridViewContentAlignment.TopCenter: case DataGridViewContentAlignment.TopLeft: case DataGridViewContentAlignment.TopRight: { fontPlacement.Y = cellBounds.Y + topMargin - fontSize.Height; break; } case DataGridViewContentAlignment.MiddleCenter: case DataGridViewContentAlignment.MiddleLeft: case DataGridViewContentAlignment.MiddleRight: case DataGridViewContentAlignment.NotSet: default: { fontPlacement.Y = cellBounds.Y + topMargin + (((float)imgHeight - fontSize.Height) / 2); break; } } // Set the X horizontal position switch (cellStyle.Alignment) { case DataGridViewContentAlignment.BottomLeft: case DataGridViewContentAlignment.MiddleLeft: case DataGridViewContentAlignment.TopLeft: { fontPlacement.X = cellBounds.X + leftMargin; break; } case DataGridViewContentAlignment.BottomRight: case DataGridViewContentAlignment.MiddleRight: case DataGridViewContentAlignment.TopRight: { fontPlacement.X = cellBounds.X + leftMargin + imgWidth - fontSize.Width; break; } case DataGridViewContentAlignment.BottomCenter: case DataGridViewContentAlignment.MiddleCenter: case DataGridViewContentAlignment.TopCenter: case DataGridViewContentAlignment.NotSet: default: { fontPlacement.X = cellBounds.X + leftMargin + (((float)imgWidth - fontSize.Width) / 2); break; } } } #endregion [Font Placement Calc] } if (progressVal <= 100) // because when job is done or in error, we set progress > 100 % to avoid displaying the progress bar { // Draw the background System.Drawing.Rectangle backRectangle = new System.Drawing.Rectangle(cellBounds.X + leftMargin, cellBounds.Y + topMargin, imgWidth, imgHeight); using (SolidBrush backgroundBrush = new SolidBrush(Color.FromKnownColor(KnownColor.LightGray))) { g.FillRectangle(backgroundBrush, backRectangle); } // Draw the progress bar if (progressWidth > 0) { System.Drawing.Rectangle progressRectangle = new System.Drawing.Rectangle(cellBounds.X + leftMargin, cellBounds.Y + topMargin, progressWidth, imgHeight); using (LinearGradientBrush progressGradientBrush = new LinearGradientBrush(progressRectangle, Color.LightGreen, Color.MediumSeaGreen, LinearGradientMode.Vertical)) { progressGradientBrush.SetBlendTriangularShape((float).5); g.FillRectangle(progressGradientBrush, progressRectangle); } } // Draw the text if (null != formattedValue && null != cellStyle) { using (SolidBrush fontBrush = new SolidBrush(cellStyle.ForeColor)) { g.DrawString(formattedValue.ToString(), cellStyle.Font, fontBrush, fontPlacement); } } } }
protected override void OnDrawItem(DrawItemEventArgs e) { Graphics grfx = e.Graphics; Rectangle rectColor = new Rectangle(e.Bounds.Left, e.Bounds.Top, 2 * e.Bounds.Height, e.Bounds.Height); rectColor.Inflate(-1, -1); Rectangle rectText = new Rectangle(e.Bounds.Left + 2 * e.Bounds.Height, e.Bounds.Top, e.Bounds.Width - 2 * e.Bounds.Height, e.Bounds.Height); if (this.Enabled) e.DrawBackground(); LinearGradientShape item = e.Index >= 0 ? (LinearGradientShape)Items[e.Index] : LinearGradientShape.Linear; Rectangle rectShape = new Rectangle(rectColor.X + rectColor.Width / 4, rectColor.Y, rectColor.Width / 2, rectColor.Height); using (LinearGradientBrush br = new LinearGradientBrush(rectShape, e.ForeColor, e.BackColor, LinearGradientMode.Horizontal)) { if (item == LinearGradientShape.Triangular) br.SetBlendTriangularShape(0.5f); else if (item == LinearGradientShape.SigmaBell) br.SetSigmaBellShape(0.5f); grfx.FillRectangle(br, rectColor); } SolidBrush foreColorBrush = new SolidBrush(e.ForeColor); grfx.DrawString(item.ToString(), Font, foreColorBrush, rectText); }
private void CreatePaintElements() { DisposeBrushes(); switch (mGradientStyle) { case GradientMode.VerticalCenter: mSteepRect1 = new Rectangle( 0, 2, mSteepWidth, this.Height / 2 + (int)(this.Height * 0.05)); mBrush1 = new LinearGradientBrush(mSteepRect1, mColor1, mColor2, LinearGradientMode.Vertical); mSteepRect2 = new Rectangle( 0, mSteepRect1.Bottom - 1, mSteepWidth, this.Height - mSteepRect1.Height - 4); mBrush2 = new LinearGradientBrush(mSteepRect2, mColor2, mColor1, LinearGradientMode.Vertical); break; case GradientMode.Vertical: mSteepRect1 = new Rectangle( 0, 3, mSteepWidth, this.Height - 7); mBrush1 = new LinearGradientBrush(mSteepRect1, mColor1, mColor2, LinearGradientMode.Vertical); mSteepRect2 = new Rectangle( -100, -100, 1, 1); mBrush2 = new LinearGradientBrush(mSteepRect2, mColor2, mColor1, LinearGradientMode.Horizontal); break; case GradientMode.Horizontal: mSteepRect1 = new Rectangle( 0, 3, mSteepWidth, this.Height - 7); // mBrush1 = new LinearGradientBrush(rTemp, mColor1, mColor2, LinearGradientMode.Horizontal); mBrush1 = new LinearGradientBrush(this.ClientRectangle, mColor1, mColor2, LinearGradientMode.Horizontal); mSteepRect2 = new Rectangle( -100, -100, 1, 1); mBrush2 = new LinearGradientBrush(mSteepRect2, Color.Red, Color.Red, LinearGradientMode.Horizontal); break; case GradientMode.HorizontalCenter: mSteepRect1 = new Rectangle( 0, 3, mSteepWidth, this.Height - 7); // mBrush1 = new LinearGradientBrush(rTemp, mColor1, mColor2, LinearGradientMode.Horizontal); mBrush1 = new LinearGradientBrush(this.ClientRectangle, mColor1, mColor2, LinearGradientMode.Horizontal); mBrush1.SetBlendTriangularShape(0.5f); mSteepRect2 = new Rectangle( -100, -100, 1, 1); mBrush2 = new LinearGradientBrush(mSteepRect2, Color.Red, Color.Red, LinearGradientMode.Horizontal); break; case GradientMode.Diagonal: mSteepRect1 = new Rectangle( 0, 3, mSteepWidth, this.Height - 7); // mBrush1 = new LinearGradientBrush(rTemp, mColor1, mColor2, LinearGradientMode.ForwardDiagonal); mBrush1 = new LinearGradientBrush(this.ClientRectangle, mColor1, mColor2, LinearGradientMode.ForwardDiagonal); // ((LinearGradientBrush) mBrush1).SetBlendTriangularShape(0.5f); mSteepRect2 = new Rectangle( -100, -100, 1, 1); mBrush2 = new LinearGradientBrush(mSteepRect2, Color.Red, Color.Red, LinearGradientMode.Horizontal); break; default: mBrush1 = new LinearGradientBrush(mSteepRect1, mColor1, mColor2, LinearGradientMode.Vertical); mBrush2 = new LinearGradientBrush(mSteepRect2, mColor2, mColor1, LinearGradientMode.Vertical); break; } innerRect = new Rectangle( this.ClientRectangle.X + 2, this.ClientRectangle.Y + 2, this.ClientRectangle.Width - 4, this.ClientRectangle.Height - 4); outnnerRect = new Rectangle( this.ClientRectangle.X, this.ClientRectangle.Y, this.ClientRectangle.Width - 1, this.ClientRectangle.Height - 1); outnnerRect2 = new Rectangle( this.ClientRectangle.X + 1, this.ClientRectangle.Y + 1, this.ClientRectangle.Width, this.ClientRectangle.Height); }
protected override void WndProc(ref Message m) { try { rangee = ClientRectangle.Width; inc = (maximum - minimum) / rangee; dra = (loopend1) / inc; dra2 = (loopstart1) / inc; //float fx = BLUE_Thumb.Width * .50f; // float fy = BLUE_Thumb.Height * .40f; //Bitmap offScreenBmp; //offScreenBmp = new Bitmap(this.Width, this.Height); //Graphics g = Graphics.FromImage(offScreenBmp); Rectangle destRect1 = new Rectangle(BLUE_Thumb.Left, BLUE_Thumb.Top, BLUE_Thumb.Width, BLUE_Thumb.Height); GraphicsPath path = new GraphicsPath(); if (tricktype == TrickType.Round) { path.AddEllipse(destRect1); } else { path.AddRectangle(destRect1); } Region reg = new Region(path); LinearGradientBrush lgb = new LinearGradientBrush(destRect1, color_Trick1, color_Trick2, 90, true); lgb.SetBlendTriangularShape(0.5f); //Graphics g = BLUE_Thumb.CreateGraphics()) //g.FillRegion(lgb, reg); BLUE_Thumb.Region = reg; switch (m.Msg) { case Api.WM_ERASEBKGND: Bitmap bmp; Rectangle srceRect; Rectangle destRect; // Create a memory bitmap to use as double buffer Bitmap offScreenBmp; offScreenBmp = new Bitmap(this.Width, this.Height); Graphics g = Graphics.FromImage(offScreenBmp); //g.SmoothingMode = SmoothingMode.AntiAlias; if (this.BackgroundImage != null) { bmp = new Bitmap(this.BackgroundImage); srceRect = new Rectangle(0, 0, bmp.Width, bmp.Height); destRect = new Rectangle(0, 0, this.Width + 100, this.Height); g.DrawImage(bmp, destRect, srceRect, GraphicsUnit.Pixel); bmp.Dispose(); } else { SolidBrush myBrush = new SolidBrush(this.BackColor); g.FillRectangle(myBrush, 0, 0, this.Width, this.Height); myBrush.Dispose(); } Pen LEFTorTOPblue = new Pen(color_LEFTorTOPblue); Pen LEFTorTOPdark = new Pen(color_LEFTorTOPdark); Pen MIDDLEblue = new Pen(color_MIDDLEblue); Pen MIDDLEdark = new Pen(color_MIDDLEdark); Pen RIGHTorBOTTOMblue = new Pen(color_RIGHTorBOTTOMblue); Pen RIGHTorBOTTOMdark = new Pen(color_RIGHTorBOTTOMdark); Pen loopred=new Pen(Color.Red); if (Orientation() == Horz) { int y = ClientRectangle.Height / 2; if (y * 2 < ClientRectangle.Height) y -= 1; if (Minimum > Maximum) { g.DrawLine(LEFTorTOPdark, new Point(0, y - 1), new Point(BLUE_Thumb.Left + BLUE_Thumb.Width / 2, y - 1)); g.DrawLine(LEFTorTOPblue, new Point(BLUE_Thumb.Left + 1 + BLUE_Thumb.Width / 2, y - 1), new Point(ClientRectangle.Width, y - 1)); g.DrawLine(MIDDLEdark, new Point(0, y), new Point(BLUE_Thumb.Left + BLUE_Thumb.Width / 2, y)); g.DrawLine(MIDDLEblue, new Point(BLUE_Thumb.Left + 1 + BLUE_Thumb.Width / 2, y), new Point(ClientRectangle.Width, y)); g.DrawLine(RIGHTorBOTTOMdark, new Point(0, y + 1), new Point(BLUE_Thumb.Left + BLUE_Thumb.Width / 2, y + 1)); g.DrawLine(RIGHTorBOTTOMblue, new Point(BLUE_Thumb.Left + 1 + BLUE_Thumb.Width / 2, y + 1), new Point(ClientRectangle.Width, y + 1)); } else { g.DrawLine(LEFTorTOPblue, new Point(0, y - 1), new Point(BLUE_Thumb.Left + BLUE_Thumb.Width / 2, y - 1)); g.DrawLine(LEFTorTOPdark, new Point(BLUE_Thumb.Left + 1 + BLUE_Thumb.Width / 2, y - 1), new Point(ClientRectangle.Width, y - 1)); g.DrawLine(MIDDLEblue, new Point(0, y), new Point(BLUE_Thumb.Left + BLUE_Thumb.Width / 2, y)); g.DrawLine(MIDDLEdark, new Point(BLUE_Thumb.Left + 1 + BLUE_Thumb.Width / 2, y), new Point(ClientRectangle.Width, y)); g.DrawLine(RIGHTorBOTTOMblue, new Point(0, y + 1), new Point(BLUE_Thumb.Left + BLUE_Thumb.Width / 2, y + 1)); g.DrawLine(RIGHTorBOTTOMdark, new Point(BLUE_Thumb.Left + 1 + BLUE_Thumb.Width / 2, y + 1), new Point(ClientRectangle.Width, y + 1)); g.DrawLine(loopred, (int)(dra), y,(int)dra2, y); } } else { int x = ClientRectangle.Width / 2; if (Minimum > Maximum) { g.DrawLine(LEFTorTOPdark, new Point(x - 1, 0), new Point(x - 1, BLUE_Thumb.Top + BLUE_Thumb.Width / 2)); g.DrawLine(LEFTorTOPblue, new Point(x - 1, BLUE_Thumb.Top + 1 + BLUE_Thumb.Width / 2), new Point(x - 1, ClientRectangle.Height)); g.DrawLine(MIDDLEdark, new Point(x, 0), new Point(x, BLUE_Thumb.Top + BLUE_Thumb.Width / 2)); g.DrawLine(MIDDLEblue, new Point(x, BLUE_Thumb.Top + 1 + BLUE_Thumb.Width / 2), new Point(x, ClientRectangle.Height)); g.DrawLine(RIGHTorBOTTOMdark, new Point(x + 1, 0), new Point(x + 1, BLUE_Thumb.Top + BLUE_Thumb.Width / 2)); g.DrawLine(RIGHTorBOTTOMblue, new Point(x + 1, BLUE_Thumb.Top + 1 + BLUE_Thumb.Width / 2), new Point(x + 1, ClientRectangle.Height)); } else { g.DrawLine(LEFTorTOPblue, new Point(x - 1, 0), new Point(x - 1, BLUE_Thumb.Top + BLUE_Thumb.Width / 2)); g.DrawLine(LEFTorTOPdark, new Point(x - 1, BLUE_Thumb.Top + 1 + BLUE_Thumb.Width / 2), new Point(x - 1, ClientRectangle.Height)); g.DrawLine(MIDDLEblue, new Point(x, 0), new Point(x, BLUE_Thumb.Top + BLUE_Thumb.Width / 2)); g.DrawLine(MIDDLEdark, new Point(x, BLUE_Thumb.Top + 1 + BLUE_Thumb.Width / 2), new Point(x, ClientRectangle.Height)); g.DrawLine(RIGHTorBOTTOMblue, new Point(x + 1, 0), new Point(x + 1, BLUE_Thumb.Top + BLUE_Thumb.Width / 2)); g.DrawLine(RIGHTorBOTTOMdark, new Point(x + 1, BLUE_Thumb.Top + 1 + BLUE_Thumb.Width / 2), new Point(x + 1, ClientRectangle.Height)); } } // Draw thumb tracker //bmp = new Bitmap(BLUE_Thumb.BackgroundImage); bmp = new Bitmap(BLUE_Thumb.Width,BLUE_Thumb.Height); bmp.MakeTransparent(Color.FromArgb(255, 0, 255)); srceRect = new Rectangle(0, 0, BLUE_Thumb.Width, BLUE_Thumb.Height); destRect = new Rectangle(BLUE_Thumb.Left, BLUE_Thumb.Top, BLUE_Thumb.Width, BLUE_Thumb.Height); path = new GraphicsPath(); if (tricktype == TrickType.Round) { path.AddEllipse(destRect); } else { path.AddRectangle(destRect); } reg = new Region(path); lgb = new LinearGradientBrush(destRect, color_Trick1, color_Trick2, 90,true); //lgb.SetBlendTriangularShape(0.5f); g.FillRegion(lgb, reg); BLUE_Thumb.Region = reg; g.DrawImage(bmp, destRect, srceRect, GraphicsUnit.Pixel); path.Dispose(); reg.Dispose(); //borderBrush.Dispose(); lgb.Dispose(); bmp.Dispose(); // Release pen resources LEFTorTOPblue.Dispose(); LEFTorTOPdark.Dispose(); MIDDLEblue.Dispose(); MIDDLEdark.Dispose(); RIGHTorBOTTOMblue.Dispose(); RIGHTorBOTTOMdark.Dispose(); // Release graphics g.Dispose(); // Swap memory bitmap (End double buffer) g = Graphics.FromHdc(m.WParam); g.DrawImage(offScreenBmp, 0, 0); g.Dispose(); offScreenBmp.Dispose(); break; default: base.WndProc(ref m); break; } } catch { }; }
private void CreatePaintElements() { DisposeBrushes(); switch (_gradientMode) { case GradientMode.VerticalCenter: _steepRect1 = new Rectangle( 0, 2, _steepWidth, this.Height / 2 + (int)(this.Height * 0.05)); _brush1 = new LinearGradientBrush(_steepRect1, _borderColor, _centerColor, LinearGradientMode.Vertical); _steepRect2 = new Rectangle( 0, _steepRect1.Bottom - 1, _steepWidth, this.Height - _steepRect1.Height - 4); _brush2 = new LinearGradientBrush(_steepRect2, _centerColor, _borderColor, LinearGradientMode.Vertical); break; case GradientMode.Vertical: _steepRect1 = new Rectangle( 0, 3, _steepWidth, this.Height - 7); _brush1 = new LinearGradientBrush(_steepRect1, _borderColor, _centerColor, LinearGradientMode.Vertical); _steepRect2 = new Rectangle( -100, -100, 1, 1); _brush2 = new LinearGradientBrush(_steepRect2, _centerColor, _borderColor, LinearGradientMode.Horizontal); break; case GradientMode.Horizontal: _steepRect1 = new Rectangle( 0, 3, _steepWidth, this.Height - 7); _brush1 = new LinearGradientBrush(this.ClientRectangle, _borderColor, _centerColor, LinearGradientMode.Horizontal); _steepRect2 = new Rectangle( -100, -100, 1, 1); _brush2 = new LinearGradientBrush(_steepRect2, Color.Red, Color.Red, LinearGradientMode.Horizontal); break; case GradientMode.HorizontalCenter: _steepRect1 = new Rectangle( 0, 3, _steepWidth, this.Height - 7); _brush1 = new LinearGradientBrush(this.ClientRectangle, _borderColor, _centerColor, LinearGradientMode.Horizontal); _brush1.SetBlendTriangularShape(0.5f); _steepRect2 = new Rectangle( -100, -100, 1, 1); _brush2 = new LinearGradientBrush(_steepRect2, Color.Red, Color.Red, LinearGradientMode.Horizontal); break; case GradientMode.Diagonal: _steepRect1 = new Rectangle( 0, 3, _steepWidth, this.Height - 7); _brush1 = new LinearGradientBrush(this.ClientRectangle, _borderColor, _centerColor, LinearGradientMode.ForwardDiagonal); _steepRect2 = new Rectangle( -100, -100, 1, 1); _brush2 = new LinearGradientBrush(_steepRect2, Color.Red, Color.Red, LinearGradientMode.Horizontal); break; default: _brush1 = new LinearGradientBrush(_steepRect1, _borderColor, _centerColor, LinearGradientMode.Vertical); _brush2 = new LinearGradientBrush(_steepRect2, _centerColor, _borderColor, LinearGradientMode.Vertical); break; } _innerRect = new Rectangle( this.ClientRectangle.X + 2, this.ClientRectangle.Y + 2, this.ClientRectangle.Width - 4, this.ClientRectangle.Height - 4); _outnnerRect = new Rectangle( this.ClientRectangle.X, this.ClientRectangle.Y, this.ClientRectangle.Width - 1, this.ClientRectangle.Height - 1); _outnnerRect2 = new Rectangle( this.ClientRectangle.X + 1, this.ClientRectangle.Y + 1, this.ClientRectangle.Width, this.ClientRectangle.Height); }