您可以更改LinkLabel控件所显示的文本以适应各种用途。 例如,通常的做法是通过将文本设置为特定颜色并加上下划线,以指示用户该文本是可点击的。 用户单击文本后,颜色将更改为其他颜色。 若要控制此行为,可以设置五个不同的属性: LinkBehavior、 LinkArea、 LinkColor、 VisitedLinkColor和 LinkVisited 属性。
更改 LinkLabel 控件的外观
将 LinkColor 和 VisitedLinkColor 属性设置为所需的颜色。
这可以通过编程方式或在设计时在 “属性” 窗口中完成。
' 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;
将 Text 属性设置为适当的题注。
这可以通过编程方式或在设计时在 “属性” 窗口中完成。
LinkLabel1.Text = "Click here to see more."
linkLabel1.Text = "Click here to see more.";
linkLabel1->Text = "Click here to see more.";
设置属性 LinkArea 以确定标题的哪个部分将指示为链接。
LinkArea 的值由 LinkArea 表示,包含两个数字:起始字符位置和字符数。 这可以通过编程方式或在设计时在 “属性” 窗口中完成。
LinkLabel1.LinkArea = new LinkArea(6,4)
linkLabel1.LinkArea = new LinkArea(6,4);
linkLabel1->LinkArea = LinkArea(6,4);
将LinkBehavior属性设置为AlwaysUnderline或 HoverUnderlineNeverUnderline。
如果设置为 HoverUnderline,则由 LinkArea 决定的标题部分只有在指针停留其上时才会显示下划线。
在事件处理程序中 LinkClicked ,将 LinkVisited 属性设置为
true
.访问链接时,通常通过颜色以某种方式更改其外观是常见的做法。 文本将更改为属性指定的 VisitedLinkColor 颜色。
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 Sub
protected 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 }