Linklabel - maximum links

R

RodBillett

Is there a limit to themaximum number of links you can add to a linklabel
control? It appears that 32 is the limit, but the error is rather strange.
Its an overflow error that occurs in the main function of th edialog!

It is real easy to reproduce! Create a window with a linklabel control on
it, and perform the following code.

Keep the loop at 31 and everything is OK, change the loop to 32 and you will
get an overflow error! I cant find anything on MSDN about this error.

Thanks
Rod


private void button2_Click(object sender, System.EventArgs e)
{
this.linkLabel1.Text = "";
this.linkLabel1.Links.Clear();

int LinkIndex;
string AddLinkString;

for ( int i = 0; i < 31; i++ )
{
this.linkLabel1.Text += "This is ";

AddLinkString = "area" + i.ToString();
LinkIndex = this.linkLabel1.Text.Length;
this.linkLabel1.Text += AddLinkString;

this.linkLabel1.Links.Add( LinkIndex, (AddLinkString.Length),
"Data" );

this.linkLabel1.Text += " of text ";
}
}
 
M

Maqsood Ahmed

Hello!
I have run this code with the loop count to 32. It adds 32 links in the
Linkbut there is an ThreadException in the application. below is the
StackTrace for the exception:

------------------------------------------------
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.PointInLink(Int32 x, Int32 y)
at System.Windows.Forms.LinkLabel.OnMouseMove(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseMove(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.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
----------------------------------------------------

Does it mean that CharacterRange length could not be greater than 31??


Maqsood Ahmed [MCP,C#]
Kolachi Advanced Technologies
http://www.kolachi.net
 
R

RodBillett

It is specifically related to the number of links added and has nothing to
do with the string length. AND am not getting Thread Exception, I am
getting a

"An unhanded exception of type 'System.OverflowException' occurred in
system.windows.forms.dll Additional information: Overflow error."



************** Exception Text **************
System.OverflowException: Overflow error.
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.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase:
file:///c:/windows/microsoft.net/framework/v1.1.4322/mscorlib.dll
----------------------------------------
LinkLabelException
Assembly Version: 1.0.1843.14415
Win32 Version: 1.0.1843.14415
CodeBase:
file:///C:/AA_NET_Examples/LinkLabelException/bin/Release/LinkLabelException.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase:
file:///c:/windows/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll
----------------------------------------
System
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase:
file:///c:/windows/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll
----------------------------------------
System.Drawing
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase:
file:///c:/windows/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll
----------------------------------------

within the Main method of the dialog.

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

A try catch within the ButtonClicked event does not catch the error.

What version of the Framework and C# did you test this on, I t might be
something that has been fixed by Microsoft already.

I am on Framework version
1.1.4322 sp1
and
Microsoft Visual C# .NET 69461-112-0750457-18289


Thanks
Rod
 
G

Guest

I ran into same limit of 32 links about 2 years ago and e-mailed Mircosoft
several times asking about it - but never got a response. A quick
work-around for me was to put 2 LinkLabels side by side so as to appear as
one to the user (I needed 36 links).

I would be nice if MS documented the limit - or better yet, remove it!
 

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