Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / April 2005

Tip: Looking for answers? Try searching our database.

Linklabel - maximum links

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RodBillett - 14 Jan 2005 23:21 GMT
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 ";
  }
}
Maqsood Ahmed - 16 Jan 2005 06:41 GMT
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
RodBillett - 17 Jan 2005 15:04 GMT
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
Jon Meyer - 12 Apr 2005 01:23 GMT
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!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.