Winforms LinkLabel Exception ~ 32 Link Maximum

  • Thread starter Thread starter Jason
  • Start date Start date
J

Jason

I'm working on a large VB.NET WinForms app, that uses the
System.Windows.Forms.LinkLabel extensively to create links within text
blocks so users can navigate around. I have come upon a major flaw in the
base LinkLabel: you can't have more than 32 links in a LinkLabel (error
producing code below).

The LinkLabel seems to accept over 32 links using the LinkLabel.Links.Add()
method. The error occurs when painting the LinkLabel (stack trace below) in
the SetMeasurableCharacterRanges function.

I read that a potential solution is to chunk the CharacterRange array:
http://www.vbug.co.uk/technicalsupport/topicposts.asp?CID=1&TID=158,
http://www.dotnet247.com/247reference/msgs/30/153947.aspx

I would assume this chunking would be done in an overriden OnPaint - has
anyone attempted this?

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim l As New LinkLabel()
Dim i As Integer
Dim startPos As Integer
Dim linkLength As Integer = 3

l.Text = "0123456789 0123456789 0123456789 0123456789 0123456789
0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
0123456789 0123456789 0123456789 0123456789"

For i = 0 To 30 'change 30 to 31 to raise overflow error
l.Links.Add(startPos, linkLength)
startPos = startPos + linkLength + 1
Next

l.Width = Me.Width
l.Height = 300
Me.Controls.Add(l)

End Sub



Message: Overflow error
Source: System.Drawing
StackTrace: " at
System.Drawing.StringFormat.SetMeasurableCharacterRanges(CharacterRange[]
ranges)
at System.Windows.Forms.LinkLabel.GetStringFormat()
at System.Windows.Forms.LinkLabel.EnsureRun(Graphics g)
at System.Windows.Forms.LinkLabel.OnPaint(PaintEventArgs e)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e,
Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Label.WndProc(Message& m)
at System.Windows.Forms.LinkLabel.WndProc(Message& msg)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.UpdateWindow(HandleRef hWnd)
at System.Windows.Forms.Control.Update()
at System.Windows.Forms.Control.Refresh()


Thanks in advance, Jason
 
Back
Top