本文整理汇总了VB.NET中System.Windows.Forms.LinkLabel.LinkClicked事件的典型用法代码示例。如果您正苦于以下问题:VB.NET LinkLabel.LinkClicked事件的具体用法?VB.NET LinkLabel.LinkClicked怎么用?VB.NET LinkLabel.LinkClicked使用的例子?那么, 这里精选的事件代码示例或许可以为您提供帮助。您也可以进一步了解该事件所在类System.Windows.Forms.LinkLabel
的用法示例。
在下文中一共展示了LinkLabel.LinkClicked事件的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Main
' 导入命名空间
Imports System.Drawing
Imports System.Windows.Forms
Public NotInheritable Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents LinkLabel1 As System.Windows.Forms.LinkLabel
<System.STAThread()> _
Public Shared Sub Main()
System.Windows.Forms.Application.Run(New Form1)
End Sub
Public Sub New()
MyBase.New()
' Create the LinkLabel.
Me.LinkLabel1 = New System.Windows.Forms.LinkLabel
' Configure the LinkLabel's location.
Me.LinkLabel1.Location = New System.Drawing.Point(34, 56)
' Specify that the size should be automatically determined by the content.
Me.LinkLabel1.AutoSize = True
' Set the text for the LinkLabel.
Me.LinkLabel1.Text = "Visit Microsoft"
' Set up how the form should be displayed and adds the controls to the form.
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.LinkLabel1})
Me.Text = "Simple Link Label Example"
End Sub
Private Sub linkLabel1_LinkClicked(ByVal sender As Object, _
ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
' Specify that the link was visited.
Me.LinkLabel1.LinkVisited = True
' Navigate to a URL.
System.Diagnostics.Process.Start("http://www.microsoft.com")
End Sub
End Class
示例2: Main
' 导入命名空间
Imports System.Drawing
Imports System.Windows.Forms
Public NotInheritable Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents LinkLabel1 As System.Windows.Forms.LinkLabel
<System.STAThread()> _
Public Shared Sub Main()
System.Windows.Forms.Application.Run(New Form1)
End Sub
Public Sub New()
MyBase.New()
Me.LinkLabel1 = New System.Windows.Forms.LinkLabel
' Configure the LinkLabel's size and location. Specify that the
' size should be automatically determined by the content.
Me.linkLabel1.Location = New System.Drawing.Point(34, 56)
Me.linkLabel1.Size = New System.Drawing.Size(224, 16)
Me.linkLabel1.AutoSize = True
' Configure the appearance.
' Set the DisabledLinkColor so that a disabled link will show up against the form's background.
Me.linkLabel1.DisabledLinkColor = System.Drawing.Color.Red
Me.linkLabel1.VisitedLinkColor = System.Drawing.Color.Blue
Me.linkLabel1.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline
Me.linkLabel1.LinkColor = System.Drawing.Color.Navy
Me.linkLabel1.TabIndex = 0
Me.linkLabel1.TabStop = True
' Identify what the first Link is.
Me.linkLabel1.LinkArea = New System.Windows.Forms.LinkArea(0, 8)
' Identify that the first link is visited already.
Me.linkLabel1.Links(0).Visited = true
' Set the Text property to a string.
Me.linkLabel1.Text = "Register Online. Visit Microsoft. Visit MSN."
' Create new links using the Add method of the LinkCollection class.
' Underline the appropriate words in the LinkLabel's Text property.
' The words 'Register', 'Microsoft', and 'MSN' will
' all be underlined and behave as hyperlinks.
' First check that the Text property is long enough to accommodate
' the desired hyperlinked areas. If it's not, don't add hyperlinks.
If Me.LinkLabel1.Text.Length >= 45 Then
Me.LinkLabel1.Links(0).LinkData = "Register"
Me.LinkLabel1.Links.Add(24, 9, "www.microsoft.com")
Me.LinkLabel1.Links.Add(42, 3, "www.msn.com")
' The second link is disabled and will appear as red.
Me.linkLabel1.Links(1).Enabled = False
End If
' Set up how the form should be displayed and adds the controls to the form.
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.LinkLabel1})
Me.Text = "Link Label Example"
End Sub
Private Sub linkLabel1_LinkClicked(ByVal sender As Object, _
ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
' Determine which link was clicked within the LinkLabel.
Me.LinkLabel1.Links(LinkLabel1.Links.IndexOf(e.Link)).Visited = True
' Displays the appropriate link based on the value of the LinkData property of the Link object.
Dim target As String = CType(e.Link.LinkData, String)
' If the value looks like a URL, navigate to it.
' Otherwise, display it in a message box.
If (target IsNot Nothing) AndAlso (target.StartsWith("www")) Then
System.Diagnostics.Process.Start(target)
Else
MessageBox.Show(("Item clicked: " + target))
End If
End Sub
End Class
示例3: MainClass
' 导入命名空间
Imports System
Imports System.Windows.Forms
Public Class MainClass
Shared Sub Main()
Dim form1 As Form = New Form1
Application.Run(form1)
End Sub
End Class
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents lnkBuy As System.Windows.Forms.LinkLabel
Friend WithEvents lnkWebSite As System.Windows.Forms.LinkLabel
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.lnkBuy = New System.Windows.Forms.LinkLabel()
Me.lnkWebSite = New System.Windows.Forms.LinkLabel()
Me.SuspendLayout()
'
'lnkBuy
'
Me.lnkBuy.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lnkBuy.LinkArea = New System.Windows.Forms.LinkArea(0, 0)
Me.lnkBuy.Location = New System.Drawing.Point(16, 60)
Me.lnkBuy.Name = "lnkBuy"
Me.lnkBuy.Size = New System.Drawing.Size(244, 48)
Me.lnkBuy.TabIndex = 3
Me.lnkBuy.Text = "www.java2s.com"
'
'lnkWebSite
'
Me.lnkWebSite.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lnkWebSite.LinkArea = New System.Windows.Forms.LinkArea(0, 0)
Me.lnkWebSite.Location = New System.Drawing.Point(16, 16)
Me.lnkWebSite.Name = "lnkWebSite"
Me.lnkWebSite.Size = New System.Drawing.Size(248, 36)
Me.lnkWebSite.TabIndex = 2
Me.lnkWebSite.Text = "The whole line is a LinkLabel"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 150)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lnkBuy, Me.lnkWebSite})
Me.Name = "Form1"
Me.Text = "Link Examples"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub lnkBuy_LinkClicked(ByVal sender As Object, _
ByVal e As LinkLabelLinkClickedEventArgs) Handles lnkBuy.LinkClicked, _
lnkWebSite.LinkClicked
e.Link.Visited = True
System.Diagnostics.Process.Start(CType(e.Link.LinkData, String))
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lnkBuy.Links.Add(0, 2, "http://www.java2s.com")
lnkBuy.Links.Add(6, 10, "http://www.java2s.com")
lnkWebSite.Links.Add(0, 10, "http://www.java2s.com")
End Sub
End Class