public void PathPaint ()
{
Int Number=the Convert. ToInt32 (AgvName. Text);
Graphics g=this. CreateGraphics ();
Pen Pen=new Pen (Brushes. Aqua);
Pen penpath=new Pen (Brushes. Green);
For (int I=AGVs [Number]. Theway. The Count () - 1; I & gt;=1; - I)
{
G.D rawLine (penpath, 35 + 30 * AGVs [Number]. Theway [I] y, 35 + 30 * AGVs [Number]. Theway [I] x, 35 + 30 * AGVs [Number]. Theway [I - 1] y, 35 + 30 * AGVs [Number]. Theway [I - 1]. X);
}
For (int I=AGVs [Number]. Theway. The Count () - 1; I & gt;=1; - I)
{
G.D rawLine (pen, 35 + 30 * AGVs [Number]. Theway [I] y, 35 + 30 * AGVs [Number]. Theway [I] x, 35 + 30 * AGVs [Number]. Theway [I - 1] y, 35 + 30 * AGVs [Number]. Theway [I - 1]. X);
//DateTime dt1=DateTime. Now;
//while ((DateTime. Now - dt1). TotalMilliseconds<3000) Application. DoEvents ();
Thread.sleep (1000);
}
}
Private void MapPrint_Click (object sender, EventArgs e)
{
Int Number=the Convert. ToInt32 (AgvName. Text);
Thread the Thread=new Thread (PathPaint);
Thread. The Start ();
}
CodePudding user response:
Don't use CreateGraphics (), but rather to provide a Paint process to system call:public partial class Form1: Form
{
Public _click ()
{
InitializeComponent();
This. Paint +=Paint process;
}
Private void Paint process (object sender, PaintEventArgs e)
{
Graphics g=um participant raphics;
//...
}
}