70-526 MCTSUse the ToolStripStatusLabel control to add Web-style links to Windows Forms applicationsAs well as the LinkLabel control, the ToolStripStatusLabel control can be used as a Label with links. Inheritance hierarchySystem.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.ToolStripItem
System.Windows.Forms.ToolStripLabel
System.Windows.Forms.ToolStripStatusLabel
Useful properties of ToolStripStatusLabelThese properties are not covered when using a ToolStripStatusLabel as a label.
Adding a LinkToolStripStatusLabel 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 manuallyThe 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
|