欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > C# >内容正文

C#

C# Tips 2------ToolStripSplitButton's 'Checked' property

发布时间:2025/3/20 C# 48 豆豆
生活随笔 收集整理的这篇文章主要介绍了 C# Tips 2------ToolStripSplitButton's 'Checked' property 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

   ToolStripSplitButton 的button 部分没有Checked propery,下列方法简单的解决这个问题:

     在button 的checkd 时,额外绘制一些图形,效果如下:

        

 

1: using System.Drawing; 2: using System.Drawing.Drawing2D; 3: using System.Windows.Forms; 4: using System.Windows.Forms.VisualStyles; 5:  6: namespace SplitButton 7: { 8: public class ToolStripSplitButtonEx : ToolStripSplitButton 9: { 10: private bool @checked = false; 11: 12: public ToolStripSplitButtonEx() 13: { 14: } 15:  16: public bool Checked 17: { 18: get { return @checked; } 19: set 20: { 21: @checked = value; 22: Invalidate(); 23: } 24: } 25:  26:  27: protected override void OnPaint(PaintEventArgs e) 28: { 29: if (@checked) 30: { 31: Rectangle rect = ButtonBounds; 32: using (Brush br = new LinearGradientBrush(rect, 33: ProfessionalColors.ButtonCheckedGradientBegin, 34: ProfessionalColors.ButtonCheckedGradientEnd, 35: LinearGradientMode.Vertical)) 36: { 37: e.Graphics.FillRectangle(br, rect); 38: } 39:  40: rect.Inflate(-1, -1); 41: e.Graphics.DrawRectangle(Pens.Black, rect); 42: 43: } 44: base.OnPaint(e); 45: } 46: } 47: }

Refences:

1.http://episteme.arstechnica.com/groupee/forums/a/tpc/f/6330927813/m/157009688731

 

转载于:https://www.cnblogs.com/janyou/archive/2008/09/26/1299283.html

总结

以上是生活随笔为你收集整理的C# Tips 2------ToolStripSplitButton's 'Checked' property的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。