* Merge winforms framework content to working branch (#14) * Breadcrumb / TOC / Move net5 to net folder (#15) * change path from net5 to net * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Add .net 5 winforms placeholder article (#16) * added some metadata and adjusted net5 placeholder * corrections * corrections * corrections * Test1 * Swapping landing page vs concept * fix links * Fix links * Fix desc
5.8 KiB
title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | dev_langs | helpviewer_keywords | ms.assetid | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Change the Appearance of LinkLabel Control | 03/30/2017 |
|
|
fdc5854f-5162-4457-8cbe-1042feb2d132 |
How to: Change the Appearance of the Windows Forms LinkLabel Control
You can change the text displayed by the xref:System.Windows.Forms.LinkLabel control to suit a variety of purposes. For example, it is common practice to indicate to the user that text can be clicked by setting the text to appear in a specific color with an underline. After the user clicks the text, the color changes to a different color. To control this behavior, you can set five different properties: the xref:System.Windows.Forms.LinkLabel.LinkBehavior%2A, xref:System.Windows.Forms.LinkLabel.LinkArea%2A, xref:System.Windows.Forms.LinkLabel.LinkColor%2A, xref:System.Windows.Forms.LinkLabel.VisitedLinkColor%2A, and xref:System.Windows.Forms.LinkLabel.LinkVisited%2A properties.
To change the appearance of a LinkLabel control
-
Set the xref:System.Windows.Forms.LinkLabel.LinkColor%2A and xref:System.Windows.Forms.LinkLabel.VisitedLinkColor%2A properties to the colors you want.
This can be done either programmatically or at design time in the Properties window.
' You can set the color using decimal values for red, green, and blue LinkLabel1.LinkColor = Color.FromArgb(0, 0, 255) ' Or you can set the color using defined constants LinkLabel1.VisitedLinkColor = Color.Purple// You can set the color using decimal values for red, green, and blue linkLabel1.LinkColor = Color.FromArgb(0, 0, 255); // Or you can set the color using defined constants linkLabel1.VisitedLinkColor = Color.Purple;// You can set the color using decimal values for red, green, and blue linkLabel1->LinkColor = Color::FromArgb(0, 0, 255); // Or you can set the color using defined constants linkLabel1->VisitedLinkColor = Color::Purple; -
Set the xref:System.Windows.Forms.LinkLabel.Text%2A property to an appropriate caption.
This can be done either programmatically or at design time in the Properties window.
LinkLabel1.Text = "Click here to see more."linkLabel1.Text = "Click here to see more.";linkLabel1->Text = "Click here to see more."; -
Set the xref:System.Windows.Forms.LinkLabel.LinkArea%2A property to determine which part of the caption will be indicated as a link.
The xref:System.Windows.Forms.LinkLabel.LinkArea%2A value is represented with a xref:System.Windows.Forms.LinkArea containing two numbers, the starting character position and the number of characters. This can be done either programmatically or at design time in the Properties window.
LinkLabel1.LinkArea = new LinkArea(6,4)linkLabel1.LinkArea = new LinkArea(6,4);linkLabel1->LinkArea = LinkArea(6,4); -
Set the xref:System.Windows.Forms.LinkLabel.LinkBehavior%2A property to xref:System.Windows.Forms.LinkBehavior.AlwaysUnderline, xref:System.Windows.Forms.LinkBehavior.HoverUnderline, or xref:System.Windows.Forms.LinkBehavior.NeverUnderline.
If it is set to xref:System.Windows.Forms.LinkBehavior.HoverUnderline, the part of the caption determined by xref:System.Windows.Forms.LinkLabel.LinkArea%2A will only be underlined when the pointer rests on it.
-
In the xref:System.Windows.Forms.LinkLabel.LinkClicked event handler, set the xref:System.Windows.Forms.LinkLabel.LinkVisited%2A property to
true.When a link has been visited, it is common practice to change its appearance in some way, usually by color. The text will change to the color specified by the xref:System.Windows.Forms.LinkLabel.VisitedLinkColor%2A property.
Protected Sub LinkLabel1_LinkClicked (ByVal sender As Object, _ ByVal e As EventArgs) Handles LinkLabel1.LinkClicked ' Change the color of the link text ' by setting LinkVisited to True. LinkLabel1.LinkVisited = True ' Then do whatever other action is appropriate End Subprotected void LinkLabel1_LinkClicked(object sender, System.EventArgs e) { // Change the color of the link text by setting LinkVisited // to True. linkLabel1.LinkVisited = true; // Then do whatever other action is appropriate }private: System::Void linkLabel1_LinkClicked(System::Object ^ sender, System::Windows::Forms::LinkLabelLinkClickedEventArgs ^ e) { // Change the color of the link text by setting LinkVisited // to True. linkLabel1->LinkVisited = true; // Then do whatever other action is appropriate }
See also
- xref:System.Windows.Forms.LinkLabel.LinkArea%2A
- xref:System.Windows.Forms.LinkLabel.LinkColor%2A
- xref:System.Windows.Forms.LinkLabel.VisitedLinkColor%2A
- xref:System.Windows.Forms.LinkLabel.LinkVisited%2A
- LinkLabel Control Overview
- How to: Link to an Object or Web Page with the Windows Forms LinkLabel Control
- LinkLabel Control