我想在c#的picturebox上画图,用DrawEllipse画点为什么picturebox上没有反应。

我想在c#的picturebox上画图
Point mypoint=new Point();
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mypoint.X = e.X;
mypoint.Y = e.Y;
}
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics g = this.CreateGraphics();
SolidBrush sb = new SolidBrush(Color.Black);
Pen mypen = new Pen(sb, 2f);
g.DrawEllipse(mypen, mypoint.X - 1, mypoint.Y - 1, 20, 20);

}
为什么picturebox没有什么反应呢
再添加一句
Point mypoint=new Point();
bool isok;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isok=true;
mypoint.X = e.X;
mypoint.Y = e.Y;
}
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
if(isok==true)
{ Graphics g = this.CreateGraphics();
SolidBrush sb = new SolidBrush(Color.Black);
Pen mypen = new Pen(sb, 2f);
g.DrawEllipse(mypen, mypoint.X - 1, mypoint.Y - 1, 20, 20);
}

}
但是picturebox没有什么反应呢

第1个回答  2010-08-21
设计视图时,点击pictureBox的事件列表,看看相应的事件是否加上了
第2个回答  2010-08-23
添加个控件timer
用tick事件代替paint事件就可以了
第3个回答  2010-08-21
如果代码没问题,那么是不是没有Invalidate()?本回答被提问者采纳
相似回答