想实现随着鼠标的拖动,画出椭圆,好像就差一点了。。。

苦茶爷爷 苦茶爷爷 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

Point P1 = new Point();
Point P2 = new Point();
bool isMouseDown = false;

private void Form1_MouseUp(object sender, MouseEventArgs e)
{
isMouseDown = false;

}

private void Form1_Load(object sender, EventArgs e)
{

}

private void Form1_Paint(object sender, PaintEventArgs e)
{

Graphics g = e.Graphics;
// Rectangle rect1 = new Rectangle(P1.X, P1.Y, P2.Y - P1.Y, P2.Y - P1.Y);
// Rectangle rect1 = new Rectangle(1, 1, 100, 100);
DrawTY(g, P1.X, P1.Y, P2.Y - P1.Y, P2.Y - P1.Y);
}

private void DrawTY(Graphics g, int a,int b,int c,int d )
{
GraphicsPath roundedRect = new GraphicsPath();
roundedRect.AddArc(a, b, c, d, 0, 360);
roundedRect.CloseFigure();

//从路径中创建区域
Region pathRegion = new Region(roundedRect);
// g.FillRegion(new SolidBrush(Color.Blue), pathRegion);
g.DrawPath(Pens.Blue, roundedRect);

}

private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (isMouseDown == false)
{
isMouseDown = true;

P1.X = e.X;
P1.Y = e.Y;
}
}

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown == true)
{

P2.X = e.X;
P2.Y = e.Y;

this.Invalidate();
}
}
}


我调用DrawTY函数,传入几个值,但是报错

为什么,我直接绘制椭圆是好的,但是通过获取坐标来绘制有问题呢?
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
苦茶爷爷
C# 111,129 成员 642,540 内容