关于 MessageBox弹出死机的问题
我在代码的按钮事件里面 弹出MessageBox 不知道 为什么就一直处于死机状态, 是不是因为重绘的原因,
我有个pictureBox触发了paint, 里面画图重绘,可是我觉得没有关联呀
paint 代码如下 大概就是利用 graphics绘图没啥别的
private void pCanvas_Paint(object sender, PaintEventArgs e)
{
////////////////////////
if (isTextChanged)
{
isTextChanged = false;
return;
}
string distEndStr = string.Empty;
List<PointF> listLPPf = new List<PointF>(); //逻辑坐标点
List<Single> listX = new List<Single>();
List<Single> listY = new List<Single>();
PointF tempPf = new PointF();
PointF middleEndPf = new PointF();
Graphics graphics = e.Graphics;
Single maxY = 0f;
Single minY = 0f;
Single maxX = 0f;
Single minX = 0f;
listPf.Clear(); //在添加之前清除
foreach (string vertex in listVertex)
{
tempPf.X = MathForPrice.CovertStrToFloat(vertex.Split(new char[] { ' ' })[0]); //取出X坐标点
tempPf.Y = MathForPrice.CovertStrToFloat(vertex.Split(new char[] { ' ' })[1]);//取出Y坐标点
listX.Add(tempPf.X); //x 坐标集合
listY.Add(tempPf.Y); // Y 坐标集合
listPf.Add(tempPf);
}
maxX = listX.Max(); //取出x坐标集合中最大的坐标
minX = listX.Min();
maxY = listY.Max();
minY = listY.Min();
centerPf.X = (maxX + minX) / 2; //虚拟坐标的中心位置
centerPf.Y = (maxY + minY) / 2;
Single coefX = this.pCanvas.Width / (maxX - minX);
Single coefY = this.pCanvas.Height / (maxY - minY);
zoom = coefX > coefY ? coefY : coefX; //按最小比例
zoom = zoom * 0.9f;// 由于显示的太边缘了,所以缩放90%
for (int i = 0; i < listPf.Count; i++)
{
tempPf = LPtoDP(listPf[i], centerPf, pCanvas, zoom); //将 逻辑坐标转换为设备坐标
listLPPf.Add(tempPf);
if (!dictForIndexAndPoint.ContainsKey(i))
{
dictForIndexAndPoint.Add(i, tempPf); //添加顶点 和顶点对应的坐标
}
}
using (Graphics gCanvas = Graphics.FromImage(bmpCanvas))
{
pCanvas.Image = bmpCanvas;
using (Pen pen = new Pen(Color.White, 1))
{
for (int i = 0; i < listLPPf.Count; i++)
{
gCanvas.DrawPolygon(pen, listLPPf.ToArray());//显示直线
}
}
if (listPf.Count > 0)
{
distEndStr = DistanceOfTwoPoints(listPf[listPf.Count - 1], listPf[0]).ToString();//最后一条线段的长度
}
if (listLPPf.Count > 0)
{
middleEndPf = MiddleOfTowPoints(listLPPf[listLPPf.Count - 1], listLPPf[0]);//最后一条线段显示所在位置
}
for (int i = 0; i < listLPPf.Count - 1; i++)
{
string distStr = DistanceOfTwoPoints(listPf[i], listPf[i + 1]).ToString();
PointF middlePf = MiddleOfTowPoints(listLPPf[i], listLPPf[i + 1]);
using (Font font = new Font("宋体", 9f))
{
gCanvas.DrawString(distStr, font, Brushes.YellowGreen, middlePf); //显示字体在线上
gCanvas.DrawString(distEndStr, font, Brushes.YellowGreen, middleEndPf);//显示最后一点与第一点连线的字
gCanvas.DrawString(i.ToString(), font, Brushes.SteelBlue, listLPPf[i]);//显示顶点的字
gCanvas.DrawString((listLPPf.Count - 1).ToString(), font, Brushes.SteelBlue, listLPPf[listLPPf.Count - 1]);
}
}
if (isDraw)//当点击画线的时候 才显示线条
{
DrawLines(gCanvas, listLPPf); //根据选择条件画线
isDraw = false;
}
using (Graphics gShow = pCanvas.CreateGraphics())
{
gShow.DrawImage(bmpCanvas, pCanvas.ClientRectangle);//将图片填充到屏幕上
}
}
}