linkLabel 用法

linkLabel 用法

Technorati 的標籤:,

linkLabel 用法

 

最簡單直接的方法是

{
	System.Diagnostics.Process.Start("www.microsoft.com");
}

 

進階:

{

	// Set the Text property to a string.

	this.linkLabel1.Text = "Register Online.  Visit Microsoft.  Visit MSN." ;

	this.linkLabel1.Links[0].LinkData = "Register Online" ;

	this.linkLabel1.Links.Add(24, 9, "www.microsoft.com" );

	this.linkLabel1.Links.Add(42, 3, "www.msn.com" );

	//  The second link is disabled and will appear as red.

	this.linkLabel1.Links[1].Enabled = false ;

}

private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)

{

	// Determine which link was clicked within the LinkLabel.

	this.linkLabel1.Links[linkLabel1.Links.IndexOf(e.Link)].Visited = true;

	// Display the appropriate link based on the value of the

	// LinkData property of the Link object.

	string target = e.Link.LinkData as string;

	// If the value looks like a URL, navigate to it.

	// Otherwise, display it in a message box.

	if (null != target && target.StartsWith( "www"))

            {

                System.Diagnostics. Process.Start(target);

            }

	else

            {

				MessageBox.Show("Item clicked: " + target);

            }

 }

詳細用法可以看MSDN:

http://msdn.microsoft.com/zh-tw/library/system.windows.forms.linklabel(v=vs.80).aspx