在panel中,放了一个picturebox,然后我在picturebox上面画红绿黄相间的矩形,画图函数如下
Pen MyPen = new Pen(Color.Black, 1);
float[] dashValue ={ 3, 3, 3, 3 };
MyPen.DashPattern = dashValue;
Graphics MyGraphics_pic1;
Graphics MyGraphics_pic2;
Graphics MyGraphics_panel1;
//处理Picturebox1的背景画图
Brush mybrush = new System.Drawing.SolidBrush(Color.Red);//故障区
Brush mybrush1 = new SolidBrush(Color.Yellow);//报警区
Brush mybrush2 = new SolidBrush(Color.Green);//合格区
//矩形的大小
float range = maxvalue - minvalue;
float a = (maxvalue - alarmvalue1) * picturebox1.Size.Height / range;
float b = (alarmvalue1 - normalvalue1) * picturebox1.Size.Height / range;
float c = (normalvalue1 - standard) * picturebox1.Size.Height / range;
float d = (standard - normalvalue2) * picturebox1.Size.Height / range;
float e = (normalvalue2 - alarmvalue2) * picturebox1.Size.Height / range;
float f = (alarmvalue2 - minvalue) * picturebox1.Size.Height / range;
//坐标
float Alarm1_Y
float Normal1_Y
float Alarm2_Y
float error_Y
//picturebox1背景画图
MyGraphics_pic1 = picturebox1.CreateGraphics();
MyGraphics_pic1.FillRectangle(mybrush, 0, 0, picturebox1.Size.Width, a);
MyGraphics_pic1.FillRectangle(mybrush1, 0, Alarm1_Y, picturebox1.Size.Width, b);
MyGraphics_pic1.FillRectangle(mybrush2, 0, Normal1_Y, picturebox1.Size.Width, d + c);
MyGraphics_pic1.FillRectangle(mybrush1, 0, Alarm2_Y, picturebox1.Size.Width, e);
MyGraphics_pic1.FillRectangle(mybrush, 0, error_Y, picturebox1.Size.Width, f); 然后,在picturebox中,当鼠标单击时,弹出一个GroupBox,通过选择项重新在picturebox以上面画的背景上绘点,当groupbox消失后就出现了一片白的不能恢复为原来的背景画面。
我在picturebox1和panel的
picturebox1.Paint += new System.Windows.Forms.PaintEventHandler(panel_back1_Paint);
panel_back1.Paint += new System.Windows.Forms.PaintEventHandler(panel_back1_Paint);
然后
private void panel_back1_Paint(object sender, PaintEventArgs e)//重绘
{
Drawback();//画背景
startdraw();//绘点
//panel_layer();
}
不好用呀
Pen MyPen = new Pen(Color.Black, 1);
float[] dashValue ={ 3, 3, 3, 3 };
MyPen.DashPattern = dashValue;
Graphics MyGraphics_pic1;
Graphics MyGraphics_pic2;
Graphics MyGraphics_panel1;
//处理Picturebox1的背景画图
Brush mybrush = new System.Drawing.SolidBrush(Color.Red);//故障区
Brush mybrush1 = new SolidBrush(Color.Yellow);//报警区
Brush mybrush2 = new SolidBrush(Color.Green);//合格区
//矩形的大小
float range = maxvalue - minvalue;
float a = (maxvalue - alarmvalue1) * picturebox1.Size.Height / range;
float b = (alarmvalue1 - normalvalue1) * picturebox1.Size.Height / range;
float c = (normalvalue1 - standard) * picturebox1.Size.Height / range;
float d = (standard - normalvalue2) * picturebox1.Size.Height / range;
float e = (normalvalue2 - alarmvalue2) * picturebox1.Size.Height / range;
float f = (alarmvalue2 - minvalue) * picturebox1.Size.Height / range;
//坐标
float Alarm1_Y
float Normal1_Y
float Alarm2_Y
float error_Y
//picturebox1背景画图
MyGraphics_pic1 = picturebox1.CreateGraphics();
MyGraphics_pic1.FillRectangle(mybrush, 0, 0, picturebox1.Size.Width, a);
MyGraphics_pic1.FillRectangle(mybrush1, 0, Alarm1_Y, picturebox1.Size.Width, b);
MyGraphics_pic1.FillRectangle(mybrush2, 0, Normal1_Y, picturebox1.Size.Width, d + c);
MyGraphics_pic1.FillRectangle(mybrush1, 0, Alarm2_Y, picturebox1.Size.Width, e);
MyGraphics_pic1.FillRectangle(mybrush, 0, error_Y, picturebox1.Size.Width, f); 然后,在picturebox中,当鼠标单击时,弹出一个GroupBox,通过选择项重新在picturebox以上面画的背景上绘点,当groupbox消失后就出现了一片白的不能恢复为原来的背景画面。
我在picturebox1和panel的
picturebox1.Paint += new System.Windows.Forms.PaintEventHandler(panel_back1_Paint);
panel_back1.Paint += new System.Windows.Forms.PaintEventHandler(panel_back1_Paint);
然后
private void panel_back1_Paint(object sender, PaintEventArgs e)//重绘
{
Drawback();//画背景
startdraw();//绘点
//panel_layer();
}
不好用呀
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货