我使用了这段代码:
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
//hide close button
pictureBox1.Visible = false;
//Take screenshoot for the DPanel.
Bitmap dend = new Bitmap(dPanel.Width, dPanel.Height);
Graphics G = Graphics.FromImage(dend);
System.Drawing.Rectangle rectangle = dPanel.RectangleToScreen(dPanel.ClientRectangle);
G.CopyFromScreen(rectangle.Location, System.Drawing.Point.Empty, dPanel.Size);
SomeGlobalVariables.Mygraph = dend;
Reporttoprint r = new Reporttoprint();
r.Show();
}
点击linkLabel1时发生异常。
似乎当我点击linkLabel1执行代码并从我的Panel拍摄时,再次调用dPanel_Paint动作然后触发异常!
该地区的例外情况:
private void dPanel_Paint(object sender, PaintEventArgs e)
{
if (k==0)
{
//add the "Group" center point to the dictionary.
ClusterPoint=new Point(((ep1.X+ep2.X)/2),((ep1.Y+ep2.Y)/2));
//Exception is done here
clusterpoints.Add(Clusterchar[k], ClusterPoint);
}
}
任何帮助
提前谢谢。
答案 0 :(得分:0)
首先,绘画事件非常频繁地发生(取决于)。
问题是您有重复的密钥。两种解决方案。
覆盖现有的键/值对:
clusterpoints[Clusterchar[k]] = ClusterPoint;
如果密钥已经存在,或者根本不添加:
var key = Clusterchar[k];
if(!clusterpoints.ContainsKey(key))
clusterpoints.Add(key, ClusterPoint);