class Cycle : Form1
{
public void Draw(Graphics G,Brush b, float x, float y, float w, float h)
{
G.FillEllipse( b, x, y, w, h);
}
}
这是我继承自Form1的Cycle类。
List<Point> star = new List<Point>();
List<Point> endd = new List<Point>();
private void Panel1_MouseDown(object sender, MouseEventArgs e)
{
moving = true;
Start = e.Location;
star.Add(e.Location);
}
private void Panel1_MouseMove(object sender, MouseEventArgs e)
{
if (moving)
{
End = e.Location;
Panel1.Invalidate();
}
}
private void Panel1_MouseUp(object sender, MouseEventArgs e)
{
endd.Add(e.Location);
moving = false;
}
这些是我的鼠标事件args,用于保存位置。
private void Panel1_Paint(object sender, PaintEventArgs e)
{
Cycle c = new Cycle();
if (End.Y > Start.Y && End.X > Start.X)
{
foreach (Point pt in star)
{
foreach(Point p in endd)
c.Draw(e.Graphics, brush, pt.X - (p.X - pt.X) / 2 - (p.Y - pt.Y) / 2, pt.Y - (p.Y - pt.Y) / 2 - (p.X - pt.X) / 2, ((p.X - pt.X) + (p.Y - pt.Y)), ((p.X - pt.X) + (p.Y - pt.Y)));
}
}
}
此代码在面板中绘制省略号。然而,第一个椭圆被绘制得很完美,但是其他椭圆变得非常大,覆盖了整个面板。
我想保留位置,因为在绘制3-4个省略号之后,我会尝试将点保存到.txt中。之后,我将加载它再次绘制。但是在绘图中存在这个问题:/