c#gdi画图如何显示到picturebox里? 50
privatevoidpictureBox1_Paint(objectsender,PaintEventArgse){Graphicsg=e.Graphics;//画板P...
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;//画板
Pen pen = new Pen(Color.DodgerBlue, 12);//画笔
g.DrawEllipse(pen, 100,100,50,50);//绘制椭圆,因为高和宽都设为一致,所以椭圆就变成圆了。
}
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.Refresh();
//this.pictureBox1.Invalidate();
}
如上,我在picturebox的Paint事件里画了个圆,但是运行后并没有在picturebox里显示出来。
这是什么原因? 展开
{
Graphics g = e.Graphics;//画板
Pen pen = new Pen(Color.DodgerBlue, 12);//画笔
g.DrawEllipse(pen, 100,100,50,50);//绘制椭圆,因为高和宽都设为一致,所以椭圆就变成圆了。
}
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.Refresh();
//this.pictureBox1.Invalidate();
}
如上,我在picturebox的Paint事件里画了个圆,但是运行后并没有在picturebox里显示出来。
这是什么原因? 展开
1个回答
展开全部
主要是picturebox在窗体初始化时就已经初始化,在button事件中不会触发.
应该是:
private void button1_Click(object sender, EventArgs e)
{
Graphics g = pictureBox1.CreateGraphics();
Pen pen = new Pen(Color.DodgerBlue, 12);//画笔
g.DrawEllipse(pen, 100,100,50,50);//
}
应该是:
private void button1_Click(object sender, EventArgs e)
{
Graphics g = pictureBox1.CreateGraphics();
Pen pen = new Pen(Color.DodgerBlue, 12);//画笔
g.DrawEllipse(pen, 100,100,50,50);//
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询