public class ShapeBase { Pen m_pen; Color m_color; float m_thinness; int m_z_index; public ShapeBase(){.........} public virtual void Draw(Control c){.........} ............ ......... } public class Point:ShapeBase { PointF m_onlyPoint; public Point():base(.......){} public override void Draw(Control c) { //..................... } } public class Line:ShapeBase { PointF m_startPoint; PointF m_stopPoint; public Line():base(......){} public override void Draw(Control c){................} }public class Form1:Form { //......................... //吧你的图形保存到这个List里。 List<ShapeBase> m_Shapes = new List<ShapeBase>(); public void DrawGraphics() { foreach(ShapeBase shape in m_Shapes) shape.Draw(this); } } 在你的Program.cs里。 static class Program { static void Main() { Form1 frm = new Form1(); frm.Show(); while(frm.Created) { frm.DrawGraphics(); Application.DoEvents(); } } }
写出不同的方法,针对你想要的效果然后在 paint 方法里根据你的条件选择方法进行调用
if(..)
方法1
else if(..)
方法2
...
...
都放在里面只能这样了
public class ShapeBase
{
Pen m_pen;
Color m_color;
float m_thinness;
int m_z_index;
public ShapeBase(){.........}
public virtual void Draw(Control c){.........}
............
.........
}
public class Point:ShapeBase
{
PointF m_onlyPoint;
public Point():base(.......){}
public override void Draw(Control c)
{
//.....................
}
}
public class Line:ShapeBase
{
PointF m_startPoint;
PointF m_stopPoint;
public Line():base(......){}
public override void Draw(Control c){................}
}public class Form1:Form
{
//.........................
//吧你的图形保存到这个List里。
List<ShapeBase> m_Shapes = new List<ShapeBase>();
public void DrawGraphics()
{
foreach(ShapeBase shape in m_Shapes)
shape.Draw(this);
}
}
在你的Program.cs里。
static class Program
{
static void Main()
{
Form1 frm = new Form1();
frm.Show();
while(frm.Created)
{
frm.DrawGraphics();
Application.DoEvents();
}
}
}