Can't have more then 32 links in LinkLabel

I hope you know already that LinkLabel throws Overflow error if you put more then 32 links in it. The error occurs when painting the LinkLabel (stack trace below) in the SetMeasurableCharacterRanges function.

This happens to be known limitation of GDI+ and the potential solution is to chunk the CharacterRange into smaller chunks.

I can't understand how it was allowed to publish this control with such obvious bug. Please advise if there is any workaround for this.

Also see here: http://www.dotnet247.com/247reference/msgs/52/262907.aspx
http://www.dotnet247.com/247reference/msgs/30/153947.aspx

   at System.Drawing.StringFormat.SetMeasurableCharacterRanges(CharacterRange[] ranges)
   at System.Windows.Forms.LinkLabel.CreateStringFormat()
   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.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at LinkLabelOverflowError.Program.Main() in S:\Tests\LinkLabelOverflowError\Program.cs:line 17
   at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()





Answer this question

Can't have more then 32 links in LinkLabel

  • g.moralis

    Hi!

    This is a limitation in the GDI+ API.  There is no workaround for this; you may need to split your link label.



  • Can't have more then 32 links in LinkLabel