protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); int w = this.BorderWidth > 0 ? this.BorderWidth : 0; Graphics g = e.Graphics; //缓冲 //BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current; //BufferedGraphics myBuffer = currentContext.Allocate(e.Graphics, e.ClipRectangle); //Graphics g = myBuffer.Graphics; GDIHelper.InitializeGraphics(g); GradientColor color = new GradientColor(this._BackBeginColor, this._BackEndColor, null, null); Rectangle rect = new Rectangle(0, 0, this.Size.Width - 1, this.Size.Height - 1); RoundRectangle roundRect = new RoundRectangle(rect, new CornerRadius(this._CornerRadius)); GDIHelper.FillRectangle(g, roundRect, color); if (this._BorderWidth > 0) { rect.X += this._BorderWidth - 1; rect.Y += this._BorderWidth - 1; rect.Width -= this._BorderWidth - 1; rect.Height -= this._BorderWidth - 1; GDIHelper.DrawPathBorder(g, new RoundRectangle(rect, new CornerRadius(this._CornerRadius)), this._BorderColor, this.BorderWidth); // 上容器的边框 Rectangle rectPanel1 = new Rectangle(0, 0, this.Panel1.Width - 1, this.Panel1.Height - 1); GDIHelper.DrawPathBorder(g, new RoundRectangle(rectPanel1, new CornerRadius(0)), this._BorderColor, this.BorderWidth); } //g.SmoothingMode = SmoothingMode.HighQuality; //g.PixelOffsetMode = PixelOffsetMode.HighSpeed; //myBuffer.Render(e.Graphics); //g.Dispose(); //myBuffer.Dispose();//释放资源 }
/// <summary> /// 绘制背景和边框等 /// </summary> /// <param name="g">The Graphics.</param> /// User:Ryan CreateTime:2011-08-01 16:47. private void DrawBackGround(Graphics g) { GDIHelper.InitializeGraphics(g); Rectangle rect = new Rectangle(1, 1, this.Width - 3, this.Height - 3); RoundRectangle roundRect = new RoundRectangle(rect, new Model.CornerRadius(this._CornerRadius)); switch (this._ControlState) { case EnumControlState.Default: if (this.FlatStyle != FlatStyle.Flat) { GDIHelper.FillRectangle(g, roundRect, SkinManager.CurrentSkin.DefaultControlColor); GDIHelper.DrawPathBorder(g, roundRect); } break; case EnumControlState.HeightLight: GDIHelper.FillRectangle(g, roundRect, SkinManager.CurrentSkin.HeightLightControlColor); GDIHelper.DrawPathBorder(g, roundRect); break; case EnumControlState.Focused: GDIHelper.FillRectangle(g, roundRect, SkinManager.CurrentSkin.FocusedControlColor); GDIHelper.DrawPathBorder(g, roundRect); GDIHelper.DrawPathInnerBorder(g, roundRect); break; } }
/// <summary> /// 绘制窗体标题栏 /// </summary> /// <param name="g">The g.</param> /// User:Ryan CreateTime:2012-8-3 22:22. private void DrawCaptionBackGround(Graphics g) { Rectangle rect = new Rectangle(0, 0, this.Width, this.CaptionHeight); Rectangle exRect = new Rectangle(rect.Left, rect.Bottom, rect.Width, 1); g.SetClip(exRect, CombineMode.Exclude); GDIHelper.FillRectangle(g, rect, SkinManager.CurrentSkin.CaptionColor); g.ResetClip(); }
/// <summary> /// 绘制按钮 /// </summary> /// <param name="g">The Graphics.</param> /// User:Ryan CreateTime:2011-08-02 14:23. private void DrawButton(Graphics g) { GDIHelper.InitializeGraphics(g); RoundRectangle btnRoundRect = new RoundRectangle(this.ButtonRect, 0); Color c = this.Enabled ? this._BackColor : SystemColors.Control; Size btnSize = new Size(20, 20); GDIHelper.FillRectangle(g, btnRoundRect, c); GDIHelper.DrawImage(g, this.ButtonRect, Properties.Resources.calendar, btnSize); }
/// <summary> /// 绘制窗体背景 /// </summary> /// <param name="g">The g.</param> /// User:Ryan CreateTime:2012-8-3 22:22. public void DrawFormBackGround(Graphics g) { Rectangle rect = new Rectangle(0, 0, this.Width - 2, this.Height - 2); if (SkinManager.CurrentSkin.BackGroundImageEnable) { GDIHelper.DrawImage(g, rect, SkinManager.CurrentSkin.BackGroundImage, SkinManager.CurrentSkin.BackGroundImageOpacity); //GDIHelper.DrawImage(g, rect, SkinManager.CurrentSkin.BackGroundImage); } else { GDIHelper.FillRectangle(g, rect, SkinManager.CurrentSkin.ThemeColor); } }
protected override void OnRenderDropDownButtonBackground(ToolStripItemRenderEventArgs e) { ToolStripItem item = e.Item; Graphics g = e.Graphics; GDIHelper.InitializeGraphics(g); Rectangle rect = new Rectangle(0, 0, item.Width - 1, item.Height - 1); RoundRectangle roundRect = new RoundRectangle(rect, this.ItemCornerRadius); if (item.Selected || item.Pressed) { GDIHelper.FillRectangle(g, roundRect, SkinManager.CurrentSkin.HeightLightControlColor); GDIHelper.DrawPathBorder(g, roundRect); } }
/// <summary> /// 绘制下拉框区域. /// </summary> /// <param name="g">The Graphics.</param> /// User:Ryan CreateTime:2011-07-29 15:44. private void DrawComboBox(Graphics g) { GDIHelper.InitializeGraphics(g); Rectangle rect = new Rectangle(Point.Empty, this.Size); rect.Width--; rect.Height--; ////背景 RoundRectangle roundRect = new RoundRectangle(rect, 0); Color backColor = this.Enabled ? this._BackColor : SystemColors.Control; g.SetClip(this.EditRect, CombineMode.Exclude); GDIHelper.FillRectangle(g, roundRect, backColor); g.ResetClip(); this.DrawButton(g); GDIHelper.DrawPathBorder(g, roundRect); }
protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e) { ToolStripItem item = e.Item; Graphics g = e.Graphics; GDIHelper.InitializeGraphics(g); Rectangle rect = new Rectangle(2, -1, item.Width - 4, item.Height + 1); RoundRectangle roundRect = new RoundRectangle(rect, new CornerRadius(0)); if (item.Selected || item.Pressed) { Color c1 = Color.FromArgb(200, SkinManager.CurrentSkin.HeightLightControlColor.First); Color c2 = Color.FromArgb(250, c1); GDIHelper.FillRectangle(g, rect, SkinManager.CurrentSkin.HeightLightControlColor); //GDIHelper.DrawPathBorder(g, roundRect); } }
/// <summary> /// 绘制复选框和内容. /// </summary> /// <param name="g">The Graphics.</param> /// User:Ryan CreateTime:2011-07-29 15:44. private void DrawContent(Graphics g) { GDIHelper.InitializeGraphics(g); int w = this.Width; int h = this.Height; Rectangle boxRect = new Rectangle(this._Margin, h / 2 - this._BoxSize.Height / 2, this._BoxSize.Width, this._BoxSize.Height); Size textSize = g.MeasureString(this.Text, this.Font).ToSize(); Rectangle textRect = new Rectangle(); textRect.X = boxRect.Right + this._Margin; textRect.Y = this._Margin; textRect.Height = this.Height - this._Margin * 2; textRect.Width = textSize.Width; RoundRectangle roundRect = new RoundRectangle(boxRect, this._CornerRadius); switch (this._ControlState) { case EnumControlState.HeightLight: //GDIHelper.DrawPathOuterBorder(g, roundRect, SkinManager.CurrentSkin.OuterBorderColor); GDIHelper.DrawPathBorder(g, roundRect, SkinManager.CurrentSkin.OuterBorderColor); GDIHelper.DrawPathInnerBorder(g, roundRect, SkinManager.CurrentSkin.HeightLightControlColor.First); break; default: GDIHelper.DrawCheckBox(g, roundRect); break; } Color c = base.Enabled ? this.ForeColor : SkinManager.CurrentSkin.UselessColor; //TextRenderer.DrawText(g, this.Text, this.Font, textRect, c, TextFormatFlags.Default); GDIHelper.DrawImageAndString(g, textRect, null, Size.Empty, this.Text, this.Font, c); switch (this.CheckState) { case System.Windows.Forms.CheckState.Checked: GDIHelper.DrawCheckedStateByImage(g, boxRect); break; case System.Windows.Forms.CheckState.Indeterminate: Rectangle innerRect = boxRect; innerRect.Inflate(-3, -3); Color cc = Color.FromArgb(46, 117, 35); GDIHelper.FillRectangle(g, new RoundRectangle(innerRect, this._CornerRadius), cc); break; } }
protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e) { ToolStripItem item = e.Item; Graphics g = e.Graphics; GDIHelper.InitializeGraphics(g); ////你真没救了!好吧,我承认我是个具有文艺气质的2B程序员 if (item.Tag != null && item.Tag.Equals("Vicky")) { int temp = item.Width >= item.Height ? item.Height : item.Width; Rectangle rect = new Rectangle(0, 0, temp, temp); rect.Inflate(-1, -1); Color c1 = Color.Empty, c2 = Color.Empty, c3 = Color.FromArgb(255, 220, 102); Blend blend = new Blend(); blend.Positions = new float[] { 0f, 0.5f, 1f }; blend.Factors = new float[] { 0.25f, 0.75f, 1f }; Color borderColor = item.Selected || item.Pressed ? Color.FromArgb(24, 116, 205) : SkinManager.CurrentSkin.BorderColor; float w = 1.0F; g.PixelOffsetMode = PixelOffsetMode.HighQuality; if (item.Selected || item.Pressed) { w = 2.0F; c1 = Color.FromArgb(255, 226, 48); c2 = Color.FromArgb(255, 220, 102); GDIHelper.DrawCrystalButton(g, rect, c1, c2, c3, blend); } using (Pen p = new Pen(borderColor, w)) { g.DrawEllipse(p, rect); } } else { Rectangle rect = new Rectangle(1, 1, item.Width - 4, item.Height - 3); RoundRectangle roundRect = new RoundRectangle(rect, this.ItemCornerRadius); if (item.Selected || item.Pressed) { GDIHelper.FillRectangle(g, roundRect, SkinManager.CurrentSkin.HeightLightControlColor); GDIHelper.DrawPathBorder(g, roundRect); } } }
/// <summary> /// 绘制按钮 /// </summary> /// <param name="g">The Graphics.</param> /// User:Ryan CreateTime:2011-08-02 14:23. private void DrawButton(Graphics g) { Rectangle btnRect; EnumControlState btnState = this.GetComboBoxButtonPressed() ? EnumControlState.HeightLight : EnumControlState.Default; btnRect = new Rectangle(this.ButtonRect.X, this.ButtonRect.Y - 1, this.ButtonRect.Width + 1 + this._Margin, this.ButtonRect.Height + 2); RoundRectangle btnRoundRect = new RoundRectangle(btnRect, new CornerRadius(0)); //Blend blend = new Blend(3); //blend.Positions = new float[] { 0f, 0.5f, 1f }; //blend.Factors = new float[] { 0f, 1f, 0f }; GDIHelper.FillRectangle(g, btnRoundRect, SkinManager.CurrentSkin.DefaultControlColor); Size btnSize = new Size(12, 7); GDIHelper.DrawArrow(g, ArrowDirection.Down, btnRect, btnSize, 0f, Color.FromArgb(30, 178, 239)); Color lineColor = SkinManager.CurrentSkin.BorderColor; GDIHelper.DrawGradientLine(g, lineColor, 90, btnRect.X, btnRect.Y, btnRect.X, btnRect.Bottom - 1); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); int w = this.BorderWidth > 0 ? this.BorderWidth : 0; Graphics g = e.Graphics; GDIHelper.InitializeGraphics(g); GradientColor color = new GradientColor(this._BackBeginColor, this._BackEndColor, null, null); Rectangle rect = new Rectangle(0, 0, this.Size.Width - 1, this.Size.Height - 1); RoundRectangle roundRect = new RoundRectangle(rect, new CornerRadius(this._CornerRadius)); GDIHelper.FillRectangle(g, roundRect, color); if (this._BorderWidth > 0) { rect.X += this._BorderWidth - 1; rect.Y += this._BorderWidth - 1; rect.Width -= this._BorderWidth - 1; rect.Height -= this._BorderWidth - 1; GDIHelper.DrawPathBorder(g, new RoundRectangle(rect, new CornerRadius(this._CornerRadius)), this._BorderColor, this.BorderWidth); } }
/// <summary> /// 绘制关闭按钮背景 /// </summary> /// <param name="g">The g.</param> /// <param name="rect">The rect.</param> /// <param name="controlState">State of the control.</param> /// <param name="radius">The radius.</param> /// User:Ryan CreateTime:2012-8-3 22:52. public void DrawCloseBox(Graphics g, Rectangle rect, EnumControlState controlState, int radius) { GradientColor color; switch (controlState) { case EnumControlState.HeightLight: color = SkinManager.CurrentSkin.CloseBoxHeightLightColor; break; case EnumControlState.Focused: color = SkinManager.CurrentSkin.CloseBoxPressedColor; break; default: color = SkinManager.CurrentSkin.ControlBoxDefaultColor; break; } Rectangle exRect = new Rectangle(rect.Left, rect.Bottom, rect.Width, 1); g.SetClip(exRect, CombineMode.Exclude); CornerRadius cr = new CornerRadius(0, radius + 2, 0, 0); GDIHelper.FillRectangle(g, new RoundRectangle(rect, cr), color); ////绘制边线 Color c1, c2; c1 = SkinManager.CurrentSkin.BorderColor; c2 = Color.FromArgb(10, c1); using (LinearGradientBrush brush = new LinearGradientBrush(rect, c1, c2, 90)) { brush.Blend.Positions = color.Positions; brush.Blend.Factors = color.Factors; using (Pen pen = new Pen(brush, 1)) { g.DrawLine(pen, rect.X, rect.Y, rect.X, rect.Bottom); } } g.ResetClip(); }