在onpaint事件中 Point center = new Point(100, 100); int r = 20; Rectangle rect = new Rectangle(center.X-r,center.Y-r,center.X+r,center.Y+r); e.Graphics.DrawEllipse(Pens.Red, rect);
以下代码实现的是以两条线交叉的点为圆心画圆,但是不对啊,麻烦给看一下,是哪错了private void button2_Click(object sender, EventArgs e) { //this.pictureBox1.Visible = false; int x1 = this.pictureBox2.Width; int y1 = this.pictureBox2.Height; int x2=this.pictureBox2.Width/2; int y2=this.pictureBox2.Height/2; Point p1 = new Point(x2, 0); Point p2 = new Point(x2, y1); Point p3 = new Point(0, y2); Point p4 = new Point(y1, y2); Graphics g = this.pictureBox2.CreateGraphics(); Pen p = new Pen(Color.Red); g.DrawLine(p, p1, p2); g.DrawLine(p, p3, p4); Point p5 = new Point(x2,y2); int r = 20; Rectangle rect = new Rectangle(p5.X - r, p5.Y - r, p5.X + r, p5.Y + r); g.DrawEllipse(Pens.Red, rect); }
int r = 20;
Rectangle rect = new Rectangle(center.X-r,center.Y-r,center.X+r,center.Y+r);
e.Graphics.DrawEllipse(Pens.Red, rect);
{
//this.pictureBox1.Visible = false;
int x1 = this.pictureBox2.Width;
int y1 = this.pictureBox2.Height;
int x2=this.pictureBox2.Width/2;
int y2=this.pictureBox2.Height/2; Point p1 = new Point(x2, 0);
Point p2 = new Point(x2, y1);
Point p3 = new Point(0, y2);
Point p4 = new Point(y1, y2); Graphics g = this.pictureBox2.CreateGraphics();
Pen p = new Pen(Color.Red);
g.DrawLine(p, p1, p2);
g.DrawLine(p, p3, p4); Point p5 = new Point(x2,y2);
int r = 20;
Rectangle rect = new Rectangle(p5.X - r, p5.Y - r, p5.X + r, p5.Y + r);
g.DrawEllipse(Pens.Red, rect);
}