4 // Permission is hereby granted, free of charge, to any person obtaining
\r
5 // a copy of this software and associated documentation files (the
\r
6 // "Software"), to deal in the Software without restriction, including
\r
7 // without limitation the rights to use, copy, modify, merge, publish,
\r
8 // distribute, sublicense, and/or sell copies of the Software, and to
\r
9 // permit persons to whom the Software is furnished to do so, subject to
\r
10 // the following conditions:
\r
12 // The above copyright notice and this permission notice shall be
\r
13 // included in all copies or substantial portions of the Software.
\r
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 // Copyright (c) 2006 Jonathan Pobst
\r
26 // Jonathan Pobst (monkey@jpobst.com)
\r
30 using System.Drawing;
\r
32 namespace System.Windows.Forms
\r
34 public class ToolStripLabel : ToolStripItem
\r
36 private Color active_link_color;
\r
37 private bool is_link;
\r
38 private LinkBehavior link_behavior;
\r
39 private Color link_color;
\r
40 private bool link_visited;
\r
41 private Color visited_link_color;
\r
43 #region Public Constructors
\r
44 public ToolStripLabel ()
\r
45 : this (String.Empty, null, false, null, String.Empty)
\r
49 public ToolStripLabel (Image image)
\r
50 : this (String.Empty, image, false, null, String.Empty)
\r
54 public ToolStripLabel (string text)
\r
55 : this (text, null, false, null, String.Empty)
\r
59 public ToolStripLabel (string text, Image image)
\r
60 : this (text, image, false, null, String.Empty)
\r
64 public ToolStripLabel (string text, Image image, bool isLink)
\r
65 : this (text, image, isLink, null, String.Empty)
\r
69 public ToolStripLabel (string text, Image image, bool isLink, EventHandler onClick)
\r
70 : this (text, image, isLink, onClick, String.Empty)
\r
74 public ToolStripLabel (string text, Image image, bool isLink, EventHandler onClick, string name)
\r
75 : base (text, image, onClick, name)
\r
77 this.active_link_color = Color.Red;
\r
78 this.is_link = isLink;
\r
79 this.link_behavior = LinkBehavior.SystemDefault;
\r
80 this.link_color = Color.Blue;
\r
81 this.link_visited = false;
\r
82 this.visited_link_color = Color.Purple;
\r
86 #region Public Properties
\r
87 public Color ActiveLinkColor {
\r
88 get { return this.active_link_color; }
\r
90 this.active_link_color = value;
\r
95 public override bool CanSelect { get { return false; } }
\r
97 public bool IsLink {
\r
98 get { return this.is_link; }
\r
100 this.is_link = value;
\r
101 this.Invalidate ();
\r
105 public LinkBehavior LinkBehavior {
\r
106 get { return this.link_behavior; }
\r
108 this.link_behavior = value;
\r
109 this.Invalidate ();
\r
113 public Color LinkColor {
\r
114 get { return this.link_color; }
\r
116 this.link_color = value;
\r
117 this.Invalidate ();
\r
121 public bool LinkVisited {
\r
122 get { return this.link_visited; }
\r
124 this.link_visited = value;
\r
125 this.Invalidate ();
\r
129 public Color VisitedLinkColor
\r
131 get { return this.visited_link_color; }
\r
133 this.visited_link_color = value;
\r
134 this.Invalidate ();
\r
139 #region Protected Methods
\r
140 protected override void OnFontChanged (EventArgs e)
\r
142 base.OnFontChanged (e);
\r
145 protected override void OnMouseEnter (EventArgs e)
\r
147 base.OnMouseEnter (e);
\r
150 protected override void OnMouseLeave (EventArgs e)
\r
152 base.OnMouseLeave (e);
\r
155 protected override void OnPaint (System.Windows.Forms.PaintEventArgs e)
\r
159 if (this.Owner != null) {
\r
160 Color font_color = this.Enabled ? this.ForeColor : SystemColors.GrayText;
\r
161 Image draw_image = this.Enabled ? this.Image : ToolStripRenderer.CreateDisabledImage (this.Image);
\r
163 this.Owner.Renderer.DrawLabelBackground (new System.Windows.Forms.ToolStripItemRenderEventArgs (e.Graphics, this));
\r
165 Rectangle text_layout_rect;
\r
166 Rectangle image_layout_rect;
\r
168 this.CalculateTextAndImageRectangles (out text_layout_rect, out image_layout_rect);
\r
170 if (image_layout_rect != Rectangle.Empty)
\r
171 this.Owner.Renderer.DrawItemImage (new System.Windows.Forms.ToolStripItemImageRenderEventArgs (e.Graphics, this, draw_image, image_layout_rect));
\r
172 if (text_layout_rect != Rectangle.Empty)
\r
173 if (this.is_link) {
\r
174 if (this.Pressed) // Mouse Down
\r
176 switch (this.link_behavior) {
\r
177 case LinkBehavior.SystemDefault:
\r
178 case LinkBehavior.AlwaysUnderline:
\r
179 case LinkBehavior.HoverUnderline:
\r
180 this.Owner.Renderer.DrawItemText (new System.Windows.Forms.ToolStripItemTextRenderEventArgs (e.Graphics, this, this.Text, text_layout_rect, this.active_link_color, new Font (this.Font, FontStyle.Underline), this.TextAlign));
\r
182 case LinkBehavior.NeverUnderline:
\r
183 this.Owner.Renderer.DrawItemText (new System.Windows.Forms.ToolStripItemTextRenderEventArgs (e.Graphics, this, this.Text, text_layout_rect, this.active_link_color, this.Font, this.TextAlign));
\r
187 else if (this.Selected) // Hover
\r
189 switch (this.link_behavior) {
\r
190 case LinkBehavior.SystemDefault:
\r
191 case LinkBehavior.AlwaysUnderline:
\r
192 case LinkBehavior.HoverUnderline:
\r
193 this.Owner.Renderer.DrawItemText (new System.Windows.Forms.ToolStripItemTextRenderEventArgs (e.Graphics, this, this.Text, text_layout_rect, this.link_color, new Font (this.Font, FontStyle.Underline), this.TextAlign));
\r
195 case LinkBehavior.NeverUnderline:
\r
196 this.Owner.Renderer.DrawItemText (new System.Windows.Forms.ToolStripItemTextRenderEventArgs (e.Graphics, this, this.Text, text_layout_rect, this.link_color, this.Font, this.TextAlign));
\r
202 if (this.link_visited) // Normal, Visited
\r
204 switch (this.link_behavior) {
\r
205 case LinkBehavior.SystemDefault:
\r
206 case LinkBehavior.AlwaysUnderline:
\r
207 this.Owner.Renderer.DrawItemText (new System.Windows.Forms.ToolStripItemTextRenderEventArgs (e.Graphics, this, this.Text, text_layout_rect, this.visited_link_color, new Font (this.Font, FontStyle.Underline), this.TextAlign));
\r
209 case LinkBehavior.NeverUnderline:
\r
210 case LinkBehavior.HoverUnderline:
\r
211 this.Owner.Renderer.DrawItemText (new System.Windows.Forms.ToolStripItemTextRenderEventArgs (e.Graphics, this, this.Text, text_layout_rect, this.visited_link_color, this.Font, this.TextAlign));
\r
217 switch (this.link_behavior) {
\r
218 case LinkBehavior.SystemDefault:
\r
219 case LinkBehavior.AlwaysUnderline:
\r
220 this.Owner.Renderer.DrawItemText (new System.Windows.Forms.ToolStripItemTextRenderEventArgs (e.Graphics, this, this.Text, text_layout_rect, this.link_color, new Font (this.Font, FontStyle.Underline), this.TextAlign));
\r
222 case LinkBehavior.NeverUnderline:
\r
223 case LinkBehavior.HoverUnderline:
\r
224 this.Owner.Renderer.DrawItemText (new System.Windows.Forms.ToolStripItemTextRenderEventArgs (e.Graphics, this, this.Text, text_layout_rect, this.link_color, this.Font, this.TextAlign));
\r
231 this.Owner.Renderer.DrawItemText (new System.Windows.Forms.ToolStripItemTextRenderEventArgs (e.Graphics, this, this.Text, text_layout_rect, font_color, this.Font, this.TextAlign));
\r