private System.Drawing.Pen pen=new System.Drawing.Pen(System.Drawing.Color.Black);
private int x=100, y=100, r=50;
private bool showcircle=false;this.pictureBox1.Paint+=new System.Windows.Forms.PaintEventHandler(this.pictureBox_Paint);
this.pictureBox1.MouseEnter +=new System.EventHandler(this.pictureBox_MouseEnter);
this.pictureBox1.MouseLeave +=new System.EventHandler(this.pictureBox_MouseLeave);private void pictureBox_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
if (this.showcircle==true)
e.Graphics.DrawEllipse(pen, x,y, r,r);
}private void pictureBox_MouseEnter(object sender,System.EventArgs e)
{
this.showcircle =true;
//如果不考虑刷新效率可以直接使用Refresh
//pictureBox1.Refresh();
pictureBox1.Invalidate(new System.Drawing.Rectangle(x-r, y-r, x+r,y+r));
}private void pictureBox_MouseLeave(object sender, System.EventArgs e)
{
this.showcircle =false;
//如果不考虑刷新效率可以直接使用Refresh
//pictureBox1.Refresh();
pictureBox1.Invalidate(new System.Drawing.Rectangle(x-r, y-r, x+r,y+r));
}
private int x=100, y=100, r=50;
private bool showcircle=false;this.pictureBox1.Paint+=new System.Windows.Forms.PaintEventHandler(this.pictureBox_Paint);
this.pictureBox1.MouseEnter +=new System.EventHandler(this.pictureBox_MouseEnter);
this.pictureBox1.MouseLeave +=new System.EventHandler(this.pictureBox_MouseLeave);private void pictureBox_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
if (this.showcircle==true)
e.Graphics.DrawEllipse(pen, x,y, r,r);
}private void pictureBox_MouseEnter(object sender,System.EventArgs e)
{
this.showcircle =true;
//如果不考虑刷新效率可以直接使用Refresh
//pictureBox1.Refresh();
pictureBox1.Invalidate(new System.Drawing.Rectangle(x-r, y-r, x+r,y+r));
}private void pictureBox_MouseLeave(object sender, System.EventArgs e)
{
this.showcircle =false;
//如果不考虑刷新效率可以直接使用Refresh
//pictureBox1.Refresh();
pictureBox1.Invalidate(new System.Drawing.Rectangle(x-r, y-r, x+r,y+r));
}
private System.Drawing.Pen pen=new System.Drawing.Pen(System.Drawing.Color.Black);
private int x=100, y=100, r=50;
private bool showcircle=false;this.pictureBox1.MouseMove +=new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);private void pictureBox_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
if (this.showcircle==true)
e.Graphics.DrawEllipse(pen, x-r,y-r, r+r,r+r);
}private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if ((e.X==100)&&(e.Y==100))
{
if (showcircle==false)
{
showcircle=true;
pictureBox1.Invalidate(new System.Drawing.Rectangle(x-r, y-r, x+r,y+r));
}
}
else if (showcircle==true)
{
showcircle=false;
pictureBox1.Invalidate(new System.Drawing.Rectangle(x-r, y-r, x+r,y+r));
}
}
{ }
{
Graphics g; g.FromHwnd=pictureBox.hwnd;
if (e.x==100 && e.y==100)
{
e.DrawEllipse(pen, x-r,y-r, r+r,r+r);
}
else
{
e.Clear();
}
}