共用方式為


HOW TO:變更 Windows Form LinkLabel 控制項的外觀

您可變更 LinkLabel 控制項顯示的文字,以配合各種用途的需求。 例如,通常您可將文字設定為以特定色彩與底線顯示,以向使用者表示可以按選該文字。 在使用者按一下文字之後,會變更為不同的色彩。 若要控制這個行為,您可以設定五種屬性:LinkBehaviorLinkAreaLinkColorVisitedLinkColorLinkVisited 屬性。

若要變更 LinkLabel 控制項的外觀

  1. LinkColorVisitedLinkColor 屬性設定為想要的色彩。

    可以利用程式設計方式或在設計階段使用 [屬性] 視窗完成這項工作。

    ' 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;
    
  2. Text 屬性設定為適當的標題。

    可以利用程式設計方式或在設計階段使用 [屬性] 視窗完成這項工作。

    LinkLabel1.Text = "Click here to see more."
    
    linkLabel1.Text = "Click here to see more.";
    
    linkLabel1->Text = "Click here to see more.";
    
  3. 設定 LinkArea 屬性,決定標題的哪個部分會表示為連結。

    LinkArea 值是以包含兩個數字、開始字元位置和字元數目的 LinkArea 所代表。 可以利用程式設計方式或在設計階段使用 [屬性] 視窗完成這項工作。

    LinkLabel1.LinkArea = new LinkArea(6,4)
    
    linkLabel1.LinkArea = new LinkArea(6,4);
    
    linkLabel1->LinkArea = LinkArea(6,4);
    
  4. LinkBehavior 屬性設定為 AlwaysUnderlineHoverUnderlineNeverUnderline

    若將它設定為 HoverUnderline,則由 LinkArea 決定的標題部分只會在指標指向它時才加上底線。

  5. 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
       }
    

請參閱

工作

HOW TO:使用 Windows Form LinkLabel 控制項連結至物件或 Web 網頁

參考

LinkLabel 控制項概觀 (Windows Form)

LinkArea

LinkColor

VisitedLinkColor

LinkVisited

其他資源

LinkLabel 控制項 (Windows Form)