Here's the setting,
I have many link labels in my form(I guess around 150 link labels). All of them will handle a click event, with the same condition when clicked. What are the possible solutions regarding to this problem. Because it's not good if I'll do it one by one.

Below is my code that will loop through all the link label's when form load:

For Each contr As Control In Me.Controls
    If TypeOf contr Is LinkLabel Then

    End If
Next

Thanks in advanced! ;)

Recommended Answers

All 3 Replies

Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
		For Each contr As Control In Me.Controls
			If TypeOf contr Is LinkLabel Then
				AddHandler CType(contr, LinkLabel).LinkClicked, AddressOf LinkLabel_LinkClicked
			End If
		Next
	End Sub

	Private Sub LinkLabel_LinkClicked(sender As System.Object, e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)
		MsgBox(String.Format("linkLabel clicked! Name: {0}",CType(sender,LinkLabel).Name))
	End Sub

Haha,,you're great dude!! Thanks for this one,.It helps me a lot.,By the way, may I ask you a question?

sure, ask ahead.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.