C# groupBox上画图问题
我是个新手,刚学C#,想做个小程序,结果卡在画图这里了、、详细情况是这样的,有一个按钮G2,点一下以后groupBoxG2隐藏,groupBox3出现,并且上面有个坐标。...
我是个新手,刚学C#, 想做个小程序,结果卡在画图这里了、、详细情况是这样的,有一个按钮G2 ,点一下以后groupBoxG2隐藏,groupBox3出现,并且上面有个坐标。但是写出来代码以后运行,groupBoxG3上没有,只有背景图片,请问怎么回事,哪里出错了?代码如下:
private void buttonG2_Click(object sender, EventArgs e)
{
this.groupBoxG2.Visible = false;
this.groupBoxG3.Visible = true;
Pen blackPen = new Pen(Color.Black, 6);
Point point0 = new Point(300, 300);
Point point1 = new Point(300, 50);
Point point2 = new Point(550, 300);
Graphics g = this.groupBoxG3.CreateGraphics();
g.DrawLine(blackPen, point0, point1);
g.DrawLine(blackPen, point0, point2);
} 展开
private void buttonG2_Click(object sender, EventArgs e)
{
this.groupBoxG2.Visible = false;
this.groupBoxG3.Visible = true;
Pen blackPen = new Pen(Color.Black, 6);
Point point0 = new Point(300, 300);
Point point1 = new Point(300, 50);
Point point2 = new Point(550, 300);
Graphics g = this.groupBoxG3.CreateGraphics();
g.DrawLine(blackPen, point0, point1);
g.DrawLine(blackPen, point0, point2);
} 展开
1个回答
展开全部
为groupBoxG3添加Paint事件处理,将作图代码移入groupBoxG3_Paint中:
private void groupBoxG3_Paint(object sender, PaintEventArgs e)
{
if(groupBoxG3.Visiable == false) return;
Pen blackPen = new Pen(Color.Black, 6);
Point point0 = new Point(300, 300);
Point point1 = new Point(300, 50);
Point point2 = new Point(550, 300);
Graphics g = this.groupBox1.CreateGraphics();
g.DrawLine(blackPen, point0, point1);
g.DrawLine(blackPen, point0, point2);
//释放使用过的作图资源
g.Dispose();
blackPen.Dispose();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询