c#画圆时怎样才能把圆心也画出来啊?代码怎么写?
1个回答
展开全部
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();
}
}
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();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询