ToolStripStatusLabel

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
Exam Prep. Guides
70-505 Study Guide
70-526 Study Guide

1. Forms Controls

2. Integrating Data
3. Printing/Reporting
4. Enhancing Usability
5. Asynchronous Prog.
6. Forms Controls
7. Configure/Deploy

edit
Exam 70-526 Preparation Guide: Create and configure menus.


Contents


A ToolStripStatusLabel control can be used as a Label with links.


Inheritance hierarchy

System.Object 
  System.MarshalByRefObject 
    System.ComponentModel.Component 
      System.Windows.Forms.ToolStripItem 
        System.Windows.Forms.ToolStripLabel 
          System.Windows.Forms.ToolStripStatusLabel


Useful properties

These properties are not covered when using a ToolStripStatusLabel as a label.

  • ActiveLinkColor - Defines the colour used to display an active link.
  • IsLink - Indicates whether the ToolStripLabel is a hyperlink.
  • LinkBehavior - Defines a value that represents the behaviour of a link. Takes a value from the LinkBehavior enumeration:
  • AlwaysUnderline - The link always displays with underlined text.
  • HoverUnderline - The link displays underlined text only when the mouse is hovered over the link text.
  • NeverUnderline - The link text is never underlined. The link can still be distinguished from other text by use of the LinkColor property of the LinkLabel control.
  • SystemDefault - The behaviour of this setting depends on the options set using the Internet Options dialog box in Control Panel or Internet Explorer.
  • LinkColor - Defines the colour used when displaying a normal link.
  • Tag - Use this to define the LinkData.
  • VisitedLinkColor - Defines the colour used when displaying a link that that has been previously visited.


Adding a Link

ToolStripStatusLabel does not have a collection of Links, hence there is no Link.LinkData property to store a web address in. So it is useful to store the web address in the Tag property instead. The link then appears as all of the Text property.


Add a ToolStripStatusLabel link to a Form manually

The MSDN page for the ToolStripStatusLabel control has the following example showing how to add a ToolStripStatusLabel to a Form.

private ToolStripStatusLabel toolStripLabel1;
private StatusStrip toolStrip1;
 
public Form1()
{
  CreateMyToolStripLinkLabel();
}
 
public void CreateMyToolStripLinkLabel()
{
  this.toolStrip1 = new StatusStrip();
  this.toolStripLabel1 = new ToolStripStatusLabel();
  
  // 
  // toolStrip1
  // 
  this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
      this.toolStripLabel1});
  this.toolStrip1.Location = new System.Drawing.Point(0, 0);
  this.toolStrip1.Name = "toolStrip1";
  this.toolStrip1.Size = new System.Drawing.Size(292, 25);
  this.toolStrip1.TabIndex = 0;
  this.toolStrip1.Text = "toolStrip1";
  // 
  // toolStripLabel1
  // 
  this.toolStripLabel1.IsLink = true;
  this.toolStripLabel1.LinkBehavior = System.Windows.Forms.LinkBehavior.AlwaysUnderline;
  this.toolStripLabel1.Name = "toolStripLabel1";
  this.toolStripLabel1.Size = new System.Drawing.Size(71, 22);
  this.toolStripLabel1.Tag = "http://search.microsoft.com/search/search.aspx?";
  this.toolStripLabel1.Text = "Search MSDN";
  this.toolStripLabel1.Click += new System.EventHandler(this.toolStripLabel1_Click);
 
  this.Controls.Add(this.toolStrip1);
}
 
private void toolStripLabel1_Click(object sender, EventArgs e)
{
  ToolStripLabel toolStripLabel1 = (ToolStripLabel)sender;
 
  // Start Internet Explorer and navigate to the URL in the
  // tag property.
  System.Diagnostics.Process.Start("IEXPLORE.EXE", toolStripLabel1.Tag.ToString());
 
  // Set the LinkVisited property to true to change the color.
  toolStripLabel1.LinkVisited = true;
}

Giving the following application:

Image:526-76.jpg


MSDN references


Previous_Page_.gif Next_Page_.gif
© 2007-2008 Mike Kitchen



Personal tools