【发布时间】:2016-11-11 05:16:20
【问题描述】:
我目前正在用 C# 制作一个使用 LinkLabels 的应用程序。我有一个函数可以为某个数组中的每个元素添加一个新链接。但是,该数组恰好有超过 32 个链接,当这种情况发生时,我会收到一个 OverflowException:
System.OverflowException:溢出错误。 在 System.Drawing.StringFormat.SetMeasurableCharacterRanges(CharacterRange[] 范围) 在 System.Windows.Forms.LinkLabel.CreateStringFormat() 在 System.Windows.Forms.LinkLabel.EnsureRun(图形 g) 在 System.Windows.Forms.LinkLabel.OnPaint(PaintEventArgs e) 在 System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e,Int16 层) 在 System.Windows.Forms.Control.WmPaint(消息和 m) 在 System.Windows.Forms.Control.WndProc(消息和 m) 在 System.Windows.Forms.Label.WndProc(消息和 m) 在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
有没有办法覆盖SetMeasurableCharacterRanges 函数。这样当字符范围超过 32 个时它不会抛出该错误?
这是我的代码示例:
int LengthCounter = 0;
llbl.Links.Clear();
string[] props = AList.ToArray();
llbl.Text = string.Join(", ", props);
foreach (var Prop in props)
{
llbl.Links.Add(LengthCounter, Prop.Length, string.Format("{0}{1}", prefix, Sanitize(Prop)));
LengthCounter += Prop.Length + 2;
}
【问题讨论】:
标签: c# .net winforms linklabel overflowexception