JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Creating a LinkLabel

You can create a link label just as you'd create a label, by dragging one onto a Windows form and entering text into its Text property. The difference here is that you also can add hyperlinks; you do that by clicking the LinkArea property in the properties window and clicking the ellipsis ("") button that appears to open the LinkArea editor you see in Figure 5.14. Select the area you want to make into a hyperlink there, and click OK. You can also set the LinkColor, VisitedLinkColor, and ActiveLinkColor properties to set the colors of the hyperlink.


Figure 5.14: The LinkArea editor.

When that hyperlink is clicked, the link label raises a LinkClicked event. In the example on the CD-ROM, LinkLabels, I want to navigate to the Coriolis Web site, www.coriolis.com, when the user clicks the hyperlink in our link label. I can do that in the LinkClicked event handler using the System.Diagnostics.Process. Start method (note that I also set the color of the hyperlink to the visited hyperlink color by setting the LinkVisited property to true):

Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, _
    ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) _
    Handles LinkLabel1.LinkClicked
    LinkLabel1.LinkVisited = True
    System.Diagnostics.Process.Start("www.coriolis.com")
End Sub

You can see the results in Figure 5.15—when the user clicks the hyperlink, their default browser will appear and navigate to www.coriolis.com.


Figure 5.15: A Link Label.

In addition, you can create link labels in code, support multiple links in one link label control, and navigate to other forms as well as URLs. See the next few topics for more information.

Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor