Home > Net >  GDI drawing problems
GDI drawing problems

Time:09-21

Inquire, I am just learning c # is not long, there is a problem that is why I click PathPaint button, in the process of it, and move the mouse to open, then before painting it didn't, that part is light blue originally began painting (0, 0)
 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;
//...
}
}

  •  Tags:  
  • C#
  • Related