70-526 MCTS


Use the ToolStripStatusLabel control to add Web-style links to Windows Forms applications

As well as the LinkLabel control, the 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 of ToolStripStatusLabel

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 behavior 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 behavior 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 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.


    MSDN references

  • ToolStripStatusLabel control


    << Previous Contents Next >>

    © Publicjoe, 2007