다음을 통해 공유


방법: Windows Forms LinkLabel 컨트롤의 모양 변경

LinkLabel 컨트롤이 표시하는 텍스트를 다양한 용도로 변경할 수 있습니다. 예를 들어 밑줄과 함께 특정 색으로 표시되도록 텍스트를 설정하여 텍스트를 클릭할 수 있음을 사용자에게 나타내는 것이 일반적인 관행입니다. 사용자가 텍스트를 클릭하면 색이 다른 색으로 변경됩니다. 이 동작을 제어하려면 다섯 가지 속성, 즉 LinkBehavior, LinkArea, LinkColor, VisitedLinkColorLinkVisited 속성을 설정할 수 있습니다.

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 속성을 AlwaysUnderline, HoverUnderline 또는 NeverUnderline으로 설정합니다.

    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  
       }  
    

참고 항목