1
Image ItemIcon ;
2
public void DrawIcon(Graphics g, Image icon, Rectangle bounds, bool selected, bool enabled, bool ischecked)
3
{
4
int iconTop = bounds.Top ;
5
int iconLeft = bounds.Left ;
6
if (enabled)
7
{
8
if (selected)
9
{
10
ControlPaint.DrawImageDisabled(g, icon, iconLeft + 1, iconTop, Color.Black);
11
g.DrawImage(icon, iconLeft, iconTop-1);
12
}
13
else
14
{
15
g.DrawImage(icon, iconLeft + 1, iconTop);
16
}
17
}
18
else
19
{
20
ControlPaint.DrawImageDisabled(g, icon, iconLeft + 1, iconTop, SystemColors.HighlightText);
21
}
22
}
23
protected override void OnDrawItem(DrawItemEventArgs e)
24
{
25
bool selected = (e.State & DrawItemState.Selected) > 0;
26
//bool toplevel = (Parent == Parent.GetMainMenu());
27
//bool hasicon = Icon != null;
28
bool enabled = Enabled;
29
try
30
{
31
32
e.Graphics.FillRectangle(BackColor, e.Bounds.X, e.Bounds.Y, e.Bounds.Width+1, e.Bounds.Height+1);
33
e.Graphics.FillRectangle(IconBackColor, e.Bounds.X, e.Bounds.Y, iconSize, e.Bounds.Height+1);
34
35
if(base.Text == "-")
36
{
37
e.Graphics.FillRectangle(new SolidBrush(MenuSplitColor), e.Bounds.X+iconSize,
38
e.Bounds.Y+2, e.Bounds.Width-iconSize, 1);
39
}
40
else
41
{
42
if(ItemIcon != null)
43
{
44
int y = e.Bounds.Y + e.Bounds.Height - ItemIcon.Height -1 ;
45
Rectangle _rectIcon = new Rectangle(e.Bounds.X+1,y,ItemIcon.Width,ItemIcon.Height);
46
//e.Graphics.DrawIconUnstretched(ItemIcon, _rectIcon);
47
DrawIcon(e.Graphics,ItemIcon,_rectIcon,selected,enabled,this.Checked);
48
}
49
50
Brush strColor = TextColor;
51
if(!enabled)
52
strColor = new SolidBrush ( SystemColors.GrayText);
53
//int fontWidth = Convert.ToInt32(e.Graphics.MeasureString(base.Text, TextFont).Height);
54
//fontWidth = e.Bounds.Y /2 - fontWidth /2 + e.Bounds.Y;
55
56
e.Graphics.DrawString(base.Text, e.Font, strColor, e.Bounds.X+iconSize +2, e.Bounds.Y + 5);
57
58
if(selected)
59
{
60
//
61
62
if(enabled)
63
{
64
e.Graphics.FillRectangle(SelectedColor, e.Bounds);
65
e.Graphics.DrawString(base.Text, e.Font, new SolidBrush (MenuTextSelectedColor), e.Bounds.X+iconSize +2, e.Bounds.Y+4);
66
}
67
e.Graphics.DrawRectangle(SelectedBroder, e.Bounds.X, e.Bounds.Y, e.Bounds.Width-1, e.Bounds.Height-1);
68
}
69
70
}
71
}
72
catch(Exception _ex)
73
{
74
}
75
}
76
77
protected override void OnMeasureItem(MeasureItemEventArgs e)
78
{
79
try
80
{
81
if(base.Text == "-")
82
{
83
e.ItemHeight = 4;
84
}
85
else
86
{
87
e.ItemHeight = 22;
88
e.ItemWidth = Convert.ToInt32(e.Graphics.MeasureString(this.Text, TextFont).Width)+40;
89
}
90
}
91
catch(Exception x)
92
{
93
System.Diagnostics.Trace.WriteLine(x.ToString(), "WpmMenuItem ("+this.Text+"): Measuring ");
94
}
95
}
Image ItemIcon ;2
public void DrawIcon(Graphics g, Image icon, Rectangle bounds, bool selected, bool enabled, bool ischecked) 3
{ 4
int iconTop = bounds.Top ; 5
int iconLeft = bounds.Left ; 6
if (enabled) 7
{ 8
if (selected) 9
{ 10
ControlPaint.DrawImageDisabled(g, icon, iconLeft + 1, iconTop, Color.Black); 11
g.DrawImage(icon, iconLeft, iconTop-1); 12
} 13
else 14
{ 15
g.DrawImage(icon, iconLeft + 1, iconTop); 16
} 17
} 18
else 19
{ 20
ControlPaint.DrawImageDisabled(g, icon, iconLeft + 1, iconTop, SystemColors.HighlightText); 21
} 22
} 23
protected override void OnDrawItem(DrawItemEventArgs e)24
{25
bool selected = (e.State & DrawItemState.Selected) > 0; 26
//bool toplevel = (Parent == Parent.GetMainMenu()); 27
//bool hasicon = Icon != null; 28
bool enabled = Enabled; 29
try30
{31

32
e.Graphics.FillRectangle(BackColor, e.Bounds.X, e.Bounds.Y, e.Bounds.Width+1, e.Bounds.Height+1);33
e.Graphics.FillRectangle(IconBackColor, e.Bounds.X, e.Bounds.Y, iconSize, e.Bounds.Height+1);34
35
if(base.Text == "-")36
{37
e.Graphics.FillRectangle(new SolidBrush(MenuSplitColor), e.Bounds.X+iconSize, 38
e.Bounds.Y+2, e.Bounds.Width-iconSize, 1);39
}40
else41
{42
if(ItemIcon != null)43
{44
int y = e.Bounds.Y + e.Bounds.Height - ItemIcon.Height -1 ;45
Rectangle _rectIcon = new Rectangle(e.Bounds.X+1,y,ItemIcon.Width,ItemIcon.Height);46
//e.Graphics.DrawIconUnstretched(ItemIcon, _rectIcon);47
DrawIcon(e.Graphics,ItemIcon,_rectIcon,selected,enabled,this.Checked);48
}49

50
Brush strColor = TextColor;51
if(!enabled)52
strColor = new SolidBrush ( SystemColors.GrayText);53
//int fontWidth = Convert.ToInt32(e.Graphics.MeasureString(base.Text, TextFont).Height);54
//fontWidth = e.Bounds.Y /2 - fontWidth /2 + e.Bounds.Y;55

56
e.Graphics.DrawString(base.Text, e.Font, strColor, e.Bounds.X+iconSize +2, e.Bounds.Y + 5);57
58
if(selected)59
{60
//61
62
if(enabled)63
{64
e.Graphics.FillRectangle(SelectedColor, e.Bounds);65
e.Graphics.DrawString(base.Text, e.Font, new SolidBrush (MenuTextSelectedColor), e.Bounds.X+iconSize +2, e.Bounds.Y+4);66
}67
e.Graphics.DrawRectangle(SelectedBroder, e.Bounds.X, e.Bounds.Y, e.Bounds.Width-1, e.Bounds.Height-1);68
}69
70
}71
}72
catch(Exception _ex)73
{74
}75
}76

77
protected override void OnMeasureItem(MeasureItemEventArgs e)78
{79
try80
{81
if(base.Text == "-")82
{83
e.ItemHeight = 4;84
}85
else86
{87
e.ItemHeight = 22;88
e.ItemWidth = Convert.ToInt32(e.Graphics.MeasureString(this.Text, TextFont).Width)+40;89
}90
}91
catch(Exception x)92
{93
System.Diagnostics.Trace.WriteLine(x.ToString(), "WpmMenuItem ("+this.Text+"): Measuring ");94
}95
}

浙公网安备 33010602011771号