470,811 Members | 1,136 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,811 developers. It's quick & easy.

Create An Event For Created LinkLabels

Hello, I was wondering if anyone can help me. I have some code where I'm
creating linklabels during runtime using filenames that in a directory. I
created a LinkClicked event but it only launches the last file that is called
in the ClickEvent. I tried placing the Event in the FOR EACH statement but
that's not helping. If interested I'm using VB2005. How can I apply a Click
Event to each LinkLabel or each linklabel to the same ClickedEvent? Can
someone help? Here is the code:

Dim mLinkLabel As LinkLabel 'declared globally

Private Sub CreateLinkLabels(ByRef strDirectory As String)
Dim strTmp, strFile As String
<Other variable declarations>

For Each strFile In Directory.GetFiles(strDirectory) 'grab each file
in the directory
If Path.GetExtension(strFile).ToLower = ".doc" Or
Path.GetExtension(strFile).ToLower = ".pdf" Then
strTmp = Path.GetFileName(strFile)
mLinkLabel = New LinkLabel

With mLinkLabel
.Name = "lnkLabel_" & i.ToString()
.Visible = True
.ActiveLinkColor = Color.Red
.DisabledLinkColor = Color.Blue
.LinkColor = Color.Blue
.VisitedLinkColor = Color.Purple
.Size = New System.Drawing.Size(intWidth, intHeight)
.Location = New System.Drawing.Point(intX, intY *
.Text = strTmp
End With

AddHandler mLinkLabel.LinkClicked, AddressOf
mLinkLabel_LinkClicked 'addhandler for click event.
intNum += 1
intIncrement += 2

'Add the linkLabels to the panel control.

End If
i += 1
tsText.Text = intNum.ToString() & " Files"
End Sub

Private Sub mLinkLabel_LinkClicked(ByVal sender As Object, ByVal e As
LinkLabelLinkClickedEventArgs) 'Handles myLinkLabel.LinkClicked

Dim lnk As LinkLabel = New LinkLabel

lnk = CType(sender, LinkLabel)

lnk.Links(lnk.Links.IndexOf(e.Link)).Visited = True

System.Diagnostics.Process.Start("C:\Documents and Settings
Documents\test\" & mLinkLabel.Text)

End Sub
Apr 13 '06 #1
0 1025

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Patrick Marti | last post: by
reply views Thread by HamuNaptra | last post: by
reply views Thread by Wajih | last post: by
reply views Thread by Andrea | last post: by
3 posts views Thread by RSB | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.