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