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);
} 展开
展开全部
为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();
}
ZESTRON
2024-09-04 广告
2024-09-04 广告
在Dr. O.K. Wack Chemie GmbH,我们高度重视ZESTRON的表界面分析技术。该技术通过深入研究材料表面与界面的性质,为提升产品质量与可靠性提供了有力支持。ZESTRON的表界面分析不仅涵盖了相变化、化学反应、吸附与解吸...
点击进入详情页
本回答由ZESTRON提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询