c#画圆时怎样才能把圆心也画出来啊?代码怎么写?
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/15 05:22:03
c#画圆时怎样才能把圆心也画出来啊?代码怎么写?
c#画圆时怎样才能把圆心也画出来啊?代码怎么写?
c#画圆时怎样才能把圆心也画出来啊?代码怎么写?
public int CursorX,CursorY,r;
public Image theimage;
public Graphics ig,g;
private void Form1_Load(object sender, System.EventArgs e)
{
theimage=new Bitmap(this.pictureBox1.ClientRectangle.Width,this.pictureBox1.ClientRectangle.Height);
ig=Graphics.FromImage(theimage);
ig.InterpolationMode=System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g=this.pictureBox1.CreateGraphics();
g.InterpolationMode=System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
}
private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(CursorMod==0)
{
CursorMod=1;
CursorX=e.X;
CursorY=e.Y;
}
else
{
CursorMod=0;
ig.DrawEllipse(new Pen(Color.Green,1),CursorX-r,CursorY-r,2*r,2*r);
pictureBox1.Image=theimage;
}
}
private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(CursorMod==1)
{
this.pictureBox1.Refresh();
r=Convert.ToInt32(Math.Sqrt(Math.Abs(e.X-CursorX)*Math.Abs(e.X-CursorX)+Math.Abs(e.Y-CursorY)*Math.Abs(e.Y-CursorY)));
g.DrawEllipse(new Pen(Color.Green,1),CursorX-r,CursorY-r,2*r,2*r);
}
else//CursorMod==0
{
this.pictureBox1.Refresh();
}
}