當(dāng)前位置:
首頁(yè) >
C# Tips 2------ToolStripSplitButton's 'Checked' property
發(fā)布時(shí)間:2025/3/20
46
豆豆
生活随笔
收集整理的這篇文章主要介紹了
C# Tips 2------ToolStripSplitButton's 'Checked' property
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?? ToolStripSplitButton 的button 部分沒有Checked propery,下列方法簡(jiǎn)單的解決這個(gè)問題:
???? 在button 的checkd 時(shí),額外繪制一些圖形,效果如下:
????????
?
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
?轉(zhuǎn)載于:https://www.cnblogs.com/janyou/archive/2008/09/26/1299283.html
總結(jié)
以上是生活随笔為你收集整理的C# Tips 2------ToolStripSplitButton's 'Checked' property的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: F5 LTM设备降级实战
- 下一篇: C#DSN操作