-
Oct 19th, 2020, 03:47 PM
#1
Thread Starter
New Member
[RESOLVED] LinkLabel formatting
Trying to format a LinkLabel as shown in the attached image and code.
As you can see it does not display the 7,8 and 9. Any suggestions would be appreciated.
VB Code:
Code:
Private Sub Set_num(k)
Dim sel
sel = Me.Controls("p" & k)
Dim num_test As New LinkLabel
num_test.Text = "1 2 3" & vbCrLf &
num_test.Text + "4 5 6" & vbCrLf &
num_test.Text + "7 8 9"
num_test.Links.Add(0, 1, "1")
num_test.Links.Add(3, 1, "2")
num_test.Links.Add(6, 1, "3")
num_test.Links.Add(9, 1, "4")
num_test.Links.Add(12, 1, "5")
num_test.Links.Add(15, 1, "6")
num_test.Links.Add(18, 1, "7")
num_test.Links.Add(21, 1, "8")
num_test.Links.Add(24, 1, "9")
sel.Controls.Add(num_test)
num_test.AutoSize = False
num_test.LinkBehavior = System.Windows.Forms.LinkBehavior.NeverUnderline
AddHandler num_test.LinkClicked, AddressOf num_test_LinkClicked
End Sub
Last edited by dday9; Oct 19th, 2020 at 04:02 PM.
-
Oct 19th, 2020, 04:04 PM
#2
Re: LinkLabel formatting
I've modified your post to include [code][/code] BB tags. In the future, please use them as it keeps your code formatted. I have a link on how to use the code formatting tags in my signature.
-
Oct 19th, 2020, 04:12 PM
#3
Re: LinkLabel formatting
In terms of your actual issue, I would guess that the 7, 8, and 9 do appear but they're being forced out of view.
You can test this by doing the following in the num_test_LinkClicked method:
Code:
Private Sub num_test_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs)
Dim linkLabel = DirectCast(sender, LinkLabel)
MessageBox.Show(linkLabel.Text)
End Sub
If you get a dialog with:
Then you know that the text is too large to fit in the container.
By the way if you're using a newer version of Visual Studio you can make the code a bit short by using:
Code:
num_test.Text = "1 2 3"
4 5 6
7 8 9"
Dim indexToData As New Dictionary(Of Integer, String) From {{ 0, "1" }, { 3, "2" }, { 6, "4" }} 'etc...
For Each pair In indexToData
num_test.Links.Add(pair.Key, 1, pair.Value)
Next
-
Oct 20th, 2020, 04:27 AM
#4
Thread Starter
New Member
Re: LinkLabel formatting
Thanks for your response. I implemented your code and confirmed the format appeared in the dialog box as shown in your reply. I initially increased the size of the container, but the output still only showed 2 lines.
I decreased the font size of num_test and the third line partially showed, but it made the text too small to be practical.
This led me to conclude it was not the container that was not formatting properly but the size of num_test linklabel within the container. Therefore, once I increased the size of num_test to height 100 and width 100 it displayed perfectly.
I will now mark this as 'RESOLVED'. Thanks once again for your quick response.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|