我目前正在C#中制作一个应用程序,它使用LinkLabels
。我有一个函数为某个数组中的每个元素添加一个新链接。但是,恰巧该数组有超过32个链接,并且发生这种情况时,我收到一个OverflowException:LinkLabel中超过32个链接?
System.OverflowException:溢出错误。 在System.Drawing.StringFormat.SetMeasurableCharacterRanges(CharacterRange []范围) 在System.Windows.Forms.LinkLabel.CreateStringFormat() 在System.Windows.Forms.LinkLabel.EnsureRun(图形克) 在System.Windows.Forms的(PaintEventArgs e) at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e,Int16 layer) 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.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;
}