Creating a LinkLabel Programmatically

G

Guest

Can someone please help with a problem that I'm having? I'm trying to create
a linklabel in VB.NET 2003 at runtime when a user clicks a button. The app
looks in a path for .doc and .pdf files and creates a linklabel for each file
name. When running the app the first name is being created but only portions
of the string is showing; and also it looks like the remaining is being
created but I can't see them it's like their cut off. Here is the code from
the button's click event:

Dim strPath As String = txtDirectory.Text.ToString()
Dim strTemp, strFile As String
Const intX As Integer = 16
Dim intY As Integer = 8
Const intHeight As Integer = 16
Const intWidth As Integer = 100
Dim intX2 As Integer = 0
Dim i As Integer

For Each strFile In Directory.GetFiles(strPath)
If Path.GetExtension(strFile).ToLower = ".doc" Or
Path.GetExtension(strFile).ToLower = ".pdf" Then
strTemp = Path.GetFileName(strFile)

Dim myLinkLabel As New LinkLabel
With myLinkLabel
.Name = "lnkLabel_" & i.ToString()
.Visible = True
.ActiveLinkColor = Color.Red
.DisabledLinkColor = Color.Blue
.LinkColor = Color.Blue
.VisitedLinkColor = Color.Purple
.Text = strTemp
End With
plMain.Controls.Add(myLinkLabel)

End If
i += 1
Next

I'm trying to set the Location.X for each created LinkLabels but VB is not
liking it. It's telling me that an integer can not be a system.drawing.point
type. What am I doing wrong?
 
C

Cerebrus

Hi,

I was working on a similar app sometime back and was facing similar
problems. Seemed to work fine, when I set the AutoSize and LinkArea
properties correctly. (Set AutoSize to True.)

You mustn't try to set the X or Y properties of the Location Property
(See "Control.Location" in MSDN help for the explanation). Instead set
it's Location to a new Point() as :

myLinkLabel.Location = New Point(intX * i, intY * i)

where i can be incremented with each label.

Hope this helps,

Regards,

Cerebrus.
 
G

Guest

Thanks Cerebrus for the help.
--
TC


Cerebrus said:
Hi,


I was working on a similar app sometime back and was facing similar
problems. Seemed to work fine, when I set the AutoSize and LinkArea
properties correctly. (Set AutoSize to True.)


You mustn't try to set the X or Y properties of the Location Property
(See "Control.Location" in MSDN help for the explanation). Instead set
it's Location to a new Point() as :

myLinkLabel.Location = New Point(intX * i, intY * i)

where i can be incremented with each label.

Hope this helps,

Regards,

Cerebrus.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top