internal static void DrawGradientRect( Graphics g, Rectangle rect, Color begin, Color end, Color border, Color innerBorder, Blend blend, System.Drawing.Drawing2D.LinearGradientMode mode, bool drawBorder, bool drawInnerBorder) { using (LinearGradientBrush brush = new LinearGradientBrush( rect, begin, end, mode)) { brush.Blend = blend; g.FillRectangle(brush, rect); } if (drawBorder) { ControlPaint.DrawBorder( g, rect, border, ButtonBorderStyle.Solid); } if (drawInnerBorder) { rect.Inflate(-1, -1); ControlPaint.DrawBorder( g, rect, border, ButtonBorderStyle.Solid); } }
internal static void RenderBackgroundInternal( Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color innerBorderColor, RoundStyle style, int roundWidth, bool drawBorder, bool drawGlass, System.Drawing.Drawing2D.LinearGradientMode mode) { RenderBackgroundInternal( g, rect, baseColor, borderColor, innerBorderColor, style, 8, 0.45f, drawBorder, drawGlass, mode); }
public static void DrawScrollBarTrack( Graphics g, Rectangle rect, Color begin, Color end, Orientation orientation) { bool bHorizontal = orientation == Orientation.Horizontal; System.Drawing.Drawing2D.LinearGradientMode mode = bHorizontal ? System.Drawing.Drawing2D.LinearGradientMode.Vertical : System.Drawing.Drawing2D.LinearGradientMode.Horizontal; Blend blend = new Blend(); blend.Factors = new float[] { 1f, 0.5f, 0f }; blend.Positions = new float[] { 0f, 0.5f, 1f }; DrawGradientRect( g, rect, begin, end, begin, begin, blend, mode, true, false); }
public GradientPanel() { //if (!DesignMode) LP.Validate(); _startColor = System.Drawing.Color.Black; _endColor = System.Drawing.Color.White; _gradientMode = System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal; }
public static void DrawScrollBarArraw( Graphics g, Rectangle rect, Color begin, Color end, Color border, Color innerBorder, Color fore, Orientation orientation, ArrowDirection arrowDirection, bool changeColor) { if (changeColor) { Color tmp = begin; begin = end; end = tmp; } bool bHorizontal = orientation == Orientation.Horizontal; System.Drawing.Drawing2D.LinearGradientMode mode = bHorizontal ? System.Drawing.Drawing2D.LinearGradientMode.Vertical : System.Drawing.Drawing2D.LinearGradientMode.Horizontal; rect.Inflate(-1, -1); Blend blend = new Blend(); blend.Factors = new float[] { 1f, 0.5f, 0f }; blend.Positions = new float[] { 0f, 0.5f, 1f }; DrawGradientRoundRect( g, rect, begin, end, border, innerBorder, blend, mode, 4, RoundStyle.All, true, true); using (SolidBrush brush = new SolidBrush(fore)) { RenderHelper.RenderArrowInternal( g, rect, arrowDirection, brush); } }
public VisualPanel() { SetStyle(ControlStyles.DoubleBuffer, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.ResizeRedraw, true); colorLeft = SystemColors.ControlLightLight; colorRight = SystemColors.Control; lgm = LinearGradientMode.Horizontal; visualStyle = true; }
internal void RenderBackgroundInternal( Graphics g, Rectangle rect, Color baseColor, Color borderColor, float basePosition, bool drawBorder, System.Drawing.Drawing2D.LinearGradientMode mode) { using (LinearGradientBrush brush = new LinearGradientBrush( rect, Color.Transparent, Color.Transparent, mode)) { Color[] colors = new Color[4]; colors[0] = GetColor(baseColor, 0, 35, 24, 9); colors[1] = GetColor(baseColor, 0, 13, 8, 3); colors[2] = baseColor; colors[3] = GetColor(baseColor, 0, 68, 69, 54); ColorBlend blend = new ColorBlend(); blend.Positions = new float[] { 0.0f, basePosition, basePosition + 0.05f, 1.0f }; blend.Colors = colors; brush.InterpolationColors = blend; g.FillRectangle(brush, rect); } if (baseColor.A > 80) { Rectangle rectTop = rect; if (mode == System.Drawing.Drawing2D.LinearGradientMode.Vertical) { rectTop.Height = (int)(rectTop.Height * basePosition); } else { rectTop.Width = (int)(rect.Width * basePosition); } using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(80, 255, 255, 255))) { g.FillRectangle(brushAlpha, rectTop); } } if (drawBorder) { using (Pen pen = new Pen(borderColor)) { g.DrawRectangle(pen, rect); } } }
public static void DrawScrollBarThumb( Graphics g, Rectangle rect, Color begin, Color end, Color border, Color innerBorder, Orientation orientation, bool changeColor) { if (changeColor) { Color tmp = begin; begin = end; end = tmp; } bool bHorizontal = orientation == Orientation.Horizontal; System.Drawing.Drawing2D.LinearGradientMode mode = bHorizontal ? System.Drawing.Drawing2D.LinearGradientMode.Vertical : System.Drawing.Drawing2D.LinearGradientMode.Horizontal; Blend blend = new Blend(); blend.Factors = new float[] { 1f, 0.5f, 0f }; blend.Positions = new float[] { 0f, 0.5f, 1f }; if (bHorizontal) { rect.Inflate(0, -1); } else { rect.Inflate(-1, 0); } DrawGradientRoundRect( g, rect, begin, end, border, innerBorder, blend, mode, 4, RoundStyle.All, true, true); }
static StyledButton() { _BttnBackFillMode = System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal; _BttnTextColor = System.Drawing.Color.FromArgb(2, 11, 16); _BttnBackColor1 = System.Drawing.Color.FromArgb(255, 255, 255); _BttnBackColor2 = System.Drawing.Color.FromArgb(255, 255, 255); _BttnBorderColor = System.Drawing.Color.FromArgb(27, 161, 226); _BttnDisableTextColor = System.Drawing.Color.Silver; _BttnDisableBackColor1 = System.Drawing.Color.FromArgb(218, 240, 251); _BttnDisableBackColor2 = System.Drawing.Color.FromArgb(218, 240, 251); _BttnDisableBorderColor = System.Drawing.Color.FromArgb(201, 233, 249); //_BttnMouseOverTextColor = System.Drawing.Color.FromArgb(75, 75, 75); //_BttnMouseOverBackColor1 = System.Drawing.Color.FromArgb(240, 240, 225); //_BttnMouseOverBackColor2 = System.Drawing.Color.FromArgb(220, 220, 205); //_BttnMouseOverBorderColor = System.Drawing.Color.FromArgb(175, 175, 160); _BttnMouseOverTextColor = System.Drawing.Color.FromArgb(255, 255, 255); _BttnMouseOverBackColor1 = System.Drawing.Color.FromArgb(60, 176, 232); _BttnMouseOverBackColor2 = System.Drawing.Color.FromArgb(60, 176, 232); _BttnMouseOverBorderColor = System.Drawing.Color.FromArgb(60, 176, 232); _BttnClickTextColor = System.Drawing.Color.FromArgb(255, 255, 255); _BttnClickBackColor1 = System.Drawing.Color.FromArgb(43, 169, 230); _BttnClickBackColor2 = System.Drawing.Color.FromArgb(43, 169, 230); _BttnClickBorderColor = System.Drawing.Color.FromArgb(43, 169, 230); //_BttnBackFillMode = System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal; //_BttnTextColor = System.Drawing.Color.FromArgb(90, 90, 90); //_BttnBackColor1 = System.Drawing.Color.FromArgb(245, 245, 245); //_BttnBackColor2 = System.Drawing.Color.FromArgb(225, 225, 225); //_BttnBorderColor = System.Drawing.Color.FromArgb(200, 200, 200); //_BttnDisableTextColor = System.Drawing.Color.Silver; //_BttnDisableBackColor1 = System.Drawing.Color.FromArgb(245, 245, 245); //_BttnDisableBackColor2 = System.Drawing.Color.FromArgb(225, 225, 225); //_BttnDisableBorderColor = System.Drawing.Color.FromArgb(200, 200, 200); ////_BttnMouseOverTextColor = System.Drawing.Color.FromArgb(75, 75, 75); ////_BttnMouseOverBackColor1 = System.Drawing.Color.FromArgb(240, 240, 225); ////_BttnMouseOverBackColor2 = System.Drawing.Color.FromArgb(220, 220, 205); ////_BttnMouseOverBorderColor = System.Drawing.Color.FromArgb(175, 175, 160); //_BttnMouseOverTextColor = System.Drawing.Color.FromArgb(75, 75, 75); //_BttnMouseOverBackColor1 = CustomColors.ButtonHoverLight; //System.Drawing.Color.FromArgb(240, 240, 225); //_BttnMouseOverBackColor2 = CustomColors.ButtonHoverLight; //System.Drawing.Color.FromArgb(220, 220, 205); //_BttnMouseOverBorderColor = System.Drawing.Color.FromArgb(175, 175, 160); //_BttnClickTextColor = System.Drawing.Color.FromArgb(90, 90, 90); //_BttnClickBackColor1 = System.Drawing.Color.FromArgb(210, 210, 210); //_BttnClickBackColor2 = System.Drawing.Color.FromArgb(190, 190, 190); //_BttnClickBorderColor = System.Drawing.Color.FromArgb(175, 175, 175); }
internal static void DrawGradientRoundRect( Graphics g, Rectangle rect, Color begin, Color end, Color border, Color innerBorder, Blend blend, System.Drawing.Drawing2D.LinearGradientMode mode, int radios, RoundStyle roundStyle, bool drawBorder, bool drawInnderBorder) { using (GraphicsPath path = GraphicsPathHelper.CreatePath( rect, radios, roundStyle, true)) { using (LinearGradientBrush brush = new LinearGradientBrush( rect, begin, end, mode)) { brush.Blend = blend; g.FillPath(brush, path); } if (drawBorder) { using (Pen pen = new Pen(border)) { g.DrawPath(pen, path); } } } if (drawInnderBorder) { rect.Inflate(-1, -1); using (GraphicsPath path = GraphicsPathHelper.CreatePath( rect, radios, roundStyle, true)) { using (Pen pen = new Pen(innerBorder)) { g.DrawPath(pen, path); } } } }
public StyledButton() { //if (!DesignMode) LP.Validate(); _BorderColor = _BttnBorderColor; _BackColor2 = _BttnBackColor2; _BackFillMode = _BttnBackFillMode; base.ForeColor = _BttnTextColor; base.BackColor = _BttnBackColor1; _BackColor2 = _BttnBackColor2; _BorderColor = _BttnBorderColor; _BackFillMode = _BttnBackFillMode; base.Font = new System.Drawing.Font("Arial", 9.0F); base.UseVisualStyleBackColor = false; base.FlatStyle = System.Windows.Forms.FlatStyle.Flat; base.ImageAlign = ContentAlignment.MiddleLeft; Invalidate(); }
public VisualMonthCalendar() { SetStyle(ControlStyles.FixedHeight, true); SetStyle(ControlStyles.FixedWidth, true); SetStyle(ControlStyles.DoubleBuffer, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.CacheText, true); SetStyle(ControlStyles.Selectable, true); InitializeComponent(); // default value for colors, etc. colorLeft = SystemColors.ControlLightLight; colorRight = SystemColors.Control; titleBarColorLeft = Color.WhiteSmoke; titleBarColorRight = Color.Silver; selectedDateForeColor = SystemColors.ActiveCaptionText; selectedDateBackColor = SystemColors.ActiveCaption; foreColor = SystemColors.ControlText; inactiveForeColor = SystemColors.GrayText; dayColor = SystemColors.Highlight; titleBarForeColor = SystemColors.ControlText; sepColorTop = Color.WhiteSmoke; sepColorBottom = Color.Silver; calGradient = LinearGradientMode.ForwardDiagonal; titleGradient = LinearGradientMode.Horizontal; calFont = SystemInformation.MenuFont; dayFont = SystemInformation.MenuFont; selectedDayFont = new Font(SystemInformation.MenuFont, FontStyle.Bold); visualStyle = true; useBaseGradient = false; // The individual days of the month are displayed via a 2-dimensional array of Label controls. for (int w = 0, y = titleBar.Height + 19; w < 6; w++) { for (int d = 0, x = 2; d < 7; d++) { dayLabels[w, d] = new DayLabel(); dayLabels[w, d].BackColor = Color.Transparent; dayLabels[w, d].TextAlign = System.Drawing.ContentAlignment.MiddleCenter; dayLabels[w, d].Size = new Size(28, 16); dayLabels[w, d].Location = new Point(x, y); dayLabels[w, d].Click += new System.EventHandler(dayClick); dayLabels[w, d].TabIndex = 1001 + d + (w * 10); x += dayLabels[w, d].Width; Controls.Add(dayLabels[w, d]); } y += dayLabels[w, 0].Height; } // Initialize day name labels for (int c = 0, xp = 2; c < 7; c++) { dayNameLabels[c] = new System.Windows.Forms.Label(); dayNameLabels[c].BackColor = Color.Transparent; dayNameLabels[c].TextAlign = System.Drawing.ContentAlignment.MiddleCenter; dayNameLabels[c].Size = new Size(28, 15); dayNameLabels[c].Location = new Point(xp, titleBar.Height + 2); Controls.Add(dayNameLabels[c]); xp += dayNameLabels[c].Width; } // default TodayDate and SelectedDate values todayDate = DateTime.Today; SelectedDate = DateTime.Today; dateTimePicker.CustomFormat = Application.CurrentCulture.DateTimeFormat.YearMonthPattern; dateTimePicker.LostFocus += new System.EventHandler(dateTimePicker_LostFocus); dateTimePicker.Leave += new System.EventHandler(dateTimePicker_LostFocus); dateTimePicker.ValueChanged += new System.EventHandler(dateTimePicker_DateChanged); }
private void DrawTabPages(Graphics g) { Rectangle tabRect; Point cusorPoint = PointToClient(MousePosition); bool hover; bool selected; bool hasSetClip = false; bool alignHorizontal = (Alignment == TabAlignment.Top || Alignment == TabAlignment.Bottom); System.Drawing.Drawing2D.LinearGradientMode mode = alignHorizontal ? System.Drawing.Drawing2D.LinearGradientMode.Vertical : System.Drawing.Drawing2D.LinearGradientMode.Horizontal; if (alignHorizontal) { IntPtr upDownButtonHandle = UpDownButtonHandle; bool hasUpDown = upDownButtonHandle != IntPtr.Zero; if (hasUpDown) { if (NativeMethods.IsWindowVisible(upDownButtonHandle)) { NativeMethods.RECT upDownButtonRect = new NativeMethods.RECT(); NativeMethods.GetWindowRect( upDownButtonHandle, ref upDownButtonRect); Rectangle upDownRect = Rectangle.FromLTRB( upDownButtonRect.Left, upDownButtonRect.Top, upDownButtonRect.Right, upDownButtonRect.Bottom); upDownRect = RectangleToClient(upDownRect); switch (Alignment) { case TabAlignment.Top: upDownRect.Y = 0; break; case TabAlignment.Bottom: upDownRect.Y = ClientRectangle.Height - DisplayRectangle.Height; break; } upDownRect.Height = ClientRectangle.Height; g.SetClip(upDownRect, CombineMode.Exclude); hasSetClip = true; } } } for (int index = 0; index < base.TabCount; index++) { TabPage page = TabPages[index]; tabRect = GetTabRect(index); hover = tabRect.Contains(cusorPoint); selected = SelectedIndex == index; Color baseColor = _baseColor; Color borderColor = _borderColor; if (selected) { baseColor = GetColor(_baseColor, 0, -45, -30, -14); } else if (hover) { baseColor = GetColor(_baseColor, 0, 35, 24, 9); } RenderTabBackgroundInternal( g, tabRect, baseColor, borderColor, .45F, mode); bool hasImage = DrawTabImage(g, page, tabRect); DrawtabText(g, page, tabRect, hasImage); } if (hasSetClip) { g.ResetClip(); } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (base.Panel1Collapsed || base.Panel2Collapsed) { return; } Rectangle rect = base.SplitterRectangle; bool bHorizontal = base.Orientation == Orientation.Horizontal; System.Drawing.Drawing2D.LinearGradientMode gradientMode = bHorizontal ? System.Drawing.Drawing2D.LinearGradientMode.Vertical : System.Drawing.Drawing2D.LinearGradientMode.Horizontal; using (LinearGradientBrush brush = new LinearGradientBrush( rect, gradientColor1, gradientColor2, gradientMode)) { Blend blend = new Blend(); blend.Positions = new float[] { 0f, .5f, 1f }; blend.Factors = new float[] { .5F, 1F, .5F }; brush.Blend = blend; e.Graphics.FillRectangle(brush, rect); } if (_collapsePanel == CollapsePanel.None) { return; } Rectangle arrowRect; Rectangle topLeftRect; Rectangle bottomRightRect; CalculateRect( CollapseRect, out arrowRect, out topLeftRect, out bottomRightRect); ArrowDirection direction = ArrowDirection.Left; switch (_collapsePanel) { case CollapsePanel.Panel1: if (bHorizontal) { direction = _spliterPanelState == SpliterPanelState.Collapsed ? ArrowDirection.Down : ArrowDirection.Up; } else { direction = _spliterPanelState == SpliterPanelState.Collapsed ? ArrowDirection.Right : ArrowDirection.Left; } break; case CollapsePanel.Panel2: if (bHorizontal) { direction = _spliterPanelState == SpliterPanelState.Collapsed ? ArrowDirection.Up : ArrowDirection.Down; } else { direction = _spliterPanelState == SpliterPanelState.Collapsed ? ArrowDirection.Left : ArrowDirection.Right; } break; } Color foreColor = _mouseState == ControlState.Hover ? Color.FromArgb(21, 66, 139) : Color.FromArgb(80, 136, 228); using (SmoothingModeGraphics sg = new SmoothingModeGraphics(e.Graphics)) { RenderHelper.RenderGrid(e.Graphics, topLeftRect, new Size(3, 3), foreColor); RenderHelper.RenderGrid(e.Graphics, bottomRightRect, new Size(3, 3), foreColor); using (Brush brush = new SolidBrush(foreColor)) { RenderHelper.RenderArrowInternal( e.Graphics, arrowRect, direction, brush); } } }
internal static void RenderBackgroundInternal( Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color innerBorderColor, RoundStyle style, int roundWidth, float basePosition, bool drawBorder, bool drawGlass, System.Drawing.Drawing2D.LinearGradientMode mode) { if (drawBorder) { rect.Width--; rect.Height--; } if (rect.Width == 0 || rect.Height == 0) { return; } using (LinearGradientBrush brush = new LinearGradientBrush( rect, Color.Transparent, Color.Transparent, mode)) { Color[] colors = new Color[4]; colors[0] = GetColor(baseColor, 0, 35, 24, 9); colors[1] = GetColor(baseColor, 0, 13, 8, 3); colors[2] = baseColor; colors[3] = GetColor(baseColor, 0, 35, 24, 9); ColorBlend blend = new ColorBlend(); blend.Positions = new float[] { 0.0f, basePosition, basePosition + 0.05f, 1.0f }; blend.Colors = colors; brush.InterpolationColors = blend; if (style != RoundStyle.None) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { g.FillPath(brush, path); } if (baseColor.A > 80) { Rectangle rectTop = rect; if (mode == System.Drawing.Drawing2D.LinearGradientMode.Vertical) { rectTop.Height = (int)(rectTop.Height * basePosition); } else { rectTop.Width = (int)(rect.Width * basePosition); } using (GraphicsPath pathTop = GraphicsPathHelper.CreatePath( rectTop, roundWidth, RoundStyle.Top, false)) { using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(128, 255, 255, 255))) { g.FillPath(brushAlpha, pathTop); } } } if (drawGlass) { RectangleF glassRect = rect; if (mode == System.Drawing.Drawing2D.LinearGradientMode.Vertical) { glassRect.Y = rect.Y + rect.Height * basePosition; glassRect.Height = (rect.Height - rect.Height * basePosition) * 2; } else { glassRect.X = rect.X + rect.Width * basePosition; glassRect.Width = (rect.Width - rect.Width * basePosition) * 2; } ControlPaintEx.DrawGlass(g, glassRect, 170, 0); } if (drawBorder) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(borderColor)) { g.DrawPath(pen, path); } } rect.Inflate(-1, -1); using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(innerBorderColor)) { g.DrawPath(pen, path); } } } } else { g.FillRectangle(brush, rect); if (baseColor.A > 80) { Rectangle rectTop = rect; if (mode == System.Drawing.Drawing2D.LinearGradientMode.Vertical) { rectTop.Height = (int)(rectTop.Height * basePosition); } else { rectTop.Width = (int)(rect.Width * basePosition); } using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(128, 255, 255, 255))) { g.FillRectangle(brushAlpha, rectTop); } } if (drawGlass) { RectangleF glassRect = rect; if (mode == System.Drawing.Drawing2D.LinearGradientMode.Vertical) { glassRect.Y = rect.Y + rect.Height * basePosition; glassRect.Height = (rect.Height - rect.Height * basePosition) * 2; } else { glassRect.X = rect.X + rect.Width * basePosition; glassRect.Width = (rect.Width - rect.Width * basePosition) * 2; } ControlPaintEx.DrawGlass(g, glassRect, 200, 0); } if (drawBorder) { using (Pen pen = new Pen(borderColor)) { g.DrawRectangle(pen, rect); } rect.Inflate(-1, -1); using (Pen pen = new Pen(innerBorderColor)) { g.DrawRectangle(pen, rect); } } } } }