To create a form, in the form, the left mouse button to pull there will be a red line, the left mouse button to stop, the red line stop,
CodePudding user response:
private void Form1_MouseMove (object sender, MouseEventArgs e) { If (e.B utton==MouseButtons. Left) { Graphics g=this. CreateGraphics (); G.D rawRectangle (new Pen (Color. Red, 1), the new Rectangle (e.X, e.Y, 1, 1)); } } CodePudding user response:
WPF word is a form, inside put a canvas and then give a left key press event, when triggered began to draw lines, left key bounce off paint, under the specific code can only be your baidu canvas drawing board, there are a lot of relevant tutorial,
CodePudding user response:
reference 1st floor Bridge_go response: private void Form1_MouseMove (object sender, MouseEventArgs e) { If (e.B utton==MouseButtons. Left) { Graphics g=this. CreateGraphics (); G.D rawRectangle (new Pen (Color. Red, 1), the new Rectangle (e.X, e.Y, 1, 1)); } } See bosses directly on the code, I suddenly think of my reply to lower the level of BBS, CodePudding user response:
reference 1st floor Bridge_go response: private void Form1_MouseMove (object sender, MouseEventArgs e) { If (e.B utton==MouseButtons. Left) { Graphics g=this. CreateGraphics (); G.D rawRectangle (new Pen (Color. Red, 1), the new Rectangle (e.X, e.Y, 1, 1)); } } Why this code to draw up some intermittent, is the problem that the mouse? CodePudding user response:
Point _lastPoint=new Point (100, 100); Private void Form1_MouseMove (object sender, MouseEventArgs e) { If (e.B utton==MouseButtons. Left) { If (_lastPoint.==X - 100) { _lastPoint=new Point (e.X, e.Y); } Graphics g=this. CreateGraphics (); G.D rawLine (new Pen (Color. Red, 1), _lastPoint. X, _lastPoint. J Y, e.X, e.Y); _lastPoint=new Point (e.X, e.Y); return; } _lastPoint=new Point (100, 100); } CodePudding user response:
reference 5 floor Bridge_go reply: Point _lastPoint=new Point (100, 100); Private void Form1_MouseMove (object sender, MouseEventArgs e) { If (e.B utton==MouseButtons. Left) { If (_lastPoint.==X - 100) { _lastPoint=new Point (e.X, e.Y); } Graphics g=this. CreateGraphics (); G.D rawLine (new Pen (Color. Red, 1), _lastPoint. X, _lastPoint. J Y, e.X, e.Y); _lastPoint=new Point (e.X, e.Y); return; } _lastPoint=new Point (100, 100); } 感谢 CodePudding user response:
reference 5 floor Bridge_go reply: Point _lastPoint=new Point (100, 100); Private void Form1_MouseMove (object sender, MouseEventArgs e) { If (e.B utton==MouseButtons. Left) { If (_lastPoint.==X - 100) { _lastPoint=new Point (e.X, e.Y); } Graphics g=this. CreateGraphics (); G.D rawLine (new Pen (Color. Red, 1), _lastPoint. X, _lastPoint. J Y, e.X, e.Y); _lastPoint=new Point (e.X, e.Y); return; } _lastPoint=new Point (100, 100); } Excuse me, what - 100 mean? Are there any special meaning? CodePudding user response:
No, it is an initial value