|
1 | | -using System; |
2 | | -using System.Collections.Generic; |
3 | | -using System.Text; |
4 | | -using System.Windows.Forms; |
5 | | -using System.Drawing; |
6 | | - |
7 | | -namespace QuickLaunch.Controls |
8 | | -{ |
9 | | - public class ToolStripGroupItem : ToolStripMenuItem |
10 | | - { |
11 | | - string _name = string.Empty; |
12 | | - string _details = string.Empty; |
13 | | - |
14 | | - public ToolStripGroupItem(string name) |
15 | | - : this(name, null, null, null) |
16 | | - { |
17 | | - |
18 | | - } |
19 | | - |
20 | | - public ToolStripGroupItem(string name, string details) |
21 | | - : this(name, details, null, null) |
22 | | - { |
23 | | - |
24 | | - } |
25 | | - |
26 | | - public ToolStripGroupItem(string name, string details, Image image) |
27 | | - : this(name, details, image, null) |
28 | | - { |
29 | | - |
30 | | - } |
31 | | - |
32 | | - public ToolStripGroupItem(string name, string details, Image image, EventHandler onClick) |
33 | | - : base(string.Format("{0} ({1})WWWWWW", name, details), image, onClick) |
34 | | - { |
35 | | - _name = name; |
36 | | - _details = string.IsNullOrEmpty(details) ? string.Empty : "(" + details + ")"; |
37 | | - } |
38 | | - |
39 | | - protected bool IsVertical |
40 | | - { |
41 | | - get { return !IsOnOverflow && Owner.Orientation != Orientation.Horizontal; } |
42 | | - } |
43 | | - |
44 | | - protected override void OnPaint(PaintEventArgs e) |
45 | | - { |
46 | | - if (!IsVertical) |
47 | | - { |
48 | | - // Draw the background |
49 | | - Owner.Renderer.DrawMenuItemBackground(new ToolStripItemRenderEventArgs(e.Graphics, this)); |
50 | | - |
51 | | - int padding = this.Owner.Padding.Left; |
52 | | - |
53 | | - // Draw the image |
54 | | - padding += 4; |
55 | | - if (Image != null) |
56 | | - e.Graphics.DrawImage(Image, padding, (e.ClipRectangle.Height - Image.Height) / 2); |
57 | | - |
58 | | - // Draw the name text |
59 | | - padding += 23; |
60 | | - Size textSize = TextRenderer.MeasureText(_name, Owner.Font); |
61 | | - Rectangle textRectangle = new Rectangle(padding, 0, textSize.Width, this.Height); |
62 | | - Owner.Renderer.DrawItemText(new ToolStripItemTextRenderEventArgs(e.Graphics, this, _name, textRectangle, Owner.ForeColor, Owner.Font, ContentAlignment.MiddleLeft)); |
63 | | - |
64 | | - // Draw the details text |
65 | | - if (!string.IsNullOrEmpty(_details)) |
66 | | - { |
67 | | - padding += textSize.Width; |
68 | | - textSize = TextRenderer.MeasureText(_details, Owner.Font); |
69 | | - textRectangle = new Rectangle(padding, 0, textSize.Width, this.Height); |
70 | | - Owner.Renderer.DrawItemText(new ToolStripItemTextRenderEventArgs(e.Graphics, this, _details, textRectangle, Color.Gray, Owner.Font, ContentAlignment.MiddleLeft)); |
71 | | - } |
72 | | - } |
73 | | - else |
74 | | - { |
75 | | - base.OnPaint(e); |
76 | | - } |
77 | | - } |
78 | | - } |
79 | | -} |
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Text; |
| 4 | +using System.Windows.Forms; |
| 5 | +using System.Drawing; |
| 6 | +using PluginCore.Helpers; |
| 7 | + |
| 8 | +namespace QuickLaunch.Controls |
| 9 | +{ |
| 10 | + public class ToolStripGroupItem : ToolStripMenuItem |
| 11 | + { |
| 12 | + string _name = string.Empty; |
| 13 | + string _details = string.Empty; |
| 14 | + |
| 15 | + public ToolStripGroupItem(string name) |
| 16 | + : this(name, null, null, null) |
| 17 | + { |
| 18 | + |
| 19 | + } |
| 20 | + |
| 21 | + public ToolStripGroupItem(string name, string details) |
| 22 | + : this(name, details, null, null) |
| 23 | + { |
| 24 | + |
| 25 | + } |
| 26 | + |
| 27 | + public ToolStripGroupItem(string name, string details, Image image) |
| 28 | + : this(name, details, image, null) |
| 29 | + { |
| 30 | + |
| 31 | + } |
| 32 | + |
| 33 | + public ToolStripGroupItem(string name, string details, Image image, EventHandler onClick) |
| 34 | + : base(string.Format("{0} ({1})WWWWWW", name, details), image, onClick) |
| 35 | + { |
| 36 | + _name = name; |
| 37 | + _details = string.IsNullOrEmpty(details) ? string.Empty : "(" + details + ")"; |
| 38 | + } |
| 39 | + |
| 40 | + protected bool IsVertical |
| 41 | + { |
| 42 | + get { return !IsOnOverflow && Owner.Orientation != Orientation.Horizontal; } |
| 43 | + } |
| 44 | + |
| 45 | + protected override void OnPaint(PaintEventArgs e) |
| 46 | + { |
| 47 | + if (!IsVertical) |
| 48 | + { |
| 49 | + // Draw the background |
| 50 | + Owner.Renderer.DrawMenuItemBackground(new ToolStripItemRenderEventArgs(e.Graphics, this)); |
| 51 | + |
| 52 | + int padding = this.Owner.Padding.Left; |
| 53 | + |
| 54 | + // Draw the image |
| 55 | + padding += ScaleHelper.Scale(4); |
| 56 | + if (Image != null) |
| 57 | + { |
| 58 | + Rectangle source = new Rectangle(0, 0, Image.Width, Image.Height); |
| 59 | + Rectangle dest = new Rectangle(new Point(padding, 0), ScaleHelper.Scale(new Size(16, 16))); |
| 60 | + dest.Offset(0, (e.ClipRectangle.Height - dest.Height) / 2); |
| 61 | + e.Graphics.DrawImage(Image, dest, source, GraphicsUnit.Pixel); |
| 62 | + } |
| 63 | + |
| 64 | + // Draw the name text |
| 65 | + padding += ScaleHelper.Scale(23); |
| 66 | + Size textSize = TextRenderer.MeasureText(_name, Owner.Font); |
| 67 | + Rectangle textRectangle = new Rectangle(padding, 0, textSize.Width, this.Height); |
| 68 | + Owner.Renderer.DrawItemText(new ToolStripItemTextRenderEventArgs(e.Graphics, this, _name, textRectangle, Owner.ForeColor, Owner.Font, ContentAlignment.MiddleLeft)); |
| 69 | + |
| 70 | + // Draw the details text |
| 71 | + if (!string.IsNullOrEmpty(_details)) |
| 72 | + { |
| 73 | + padding += textSize.Width; |
| 74 | + textSize = TextRenderer.MeasureText(_details, Owner.Font); |
| 75 | + textRectangle = new Rectangle(padding, 0, textSize.Width, this.Height); |
| 76 | + Owner.Renderer.DrawItemText(new ToolStripItemTextRenderEventArgs(e.Graphics, this, _details, textRectangle, Color.Gray, Owner.Font, ContentAlignment.MiddleLeft)); |
| 77 | + } |
| 78 | + } |
| 79 | + else |
| 80 | + { |
| 81 | + base.OnPaint(e); |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | +} |
0 commit comments