Drawing line in running time [modified]
-
hi all, i write this code to draw line by mouse and the drawline method is in the onPaint() method,this code is working properly but has two problems so is there any other idea to code it
private void mainScreen_MouseMove(object sender, MouseEventArgs e) { /// Determine the End point of the line if (lineFlag == 1 && !(mLineBeginPnt.IsEmpty) && nextLineFlag == 1) { Graphics grfx = this.CreateGraphics(); Pen pen = new Pen(mainScreen.DefaultBackColor, 2); userInterface.handleMouseMove(grfx, ref lastPntOfLine, ref lastPntCounter, pen, ref mLineEndPnt, mLineBeginPnt, e.Location); pen.Dispose(); grfx.Dispose(); Invalidate(drawingFrame); } } ---------------------------------------- public void handleMouseMove(Graphics grfx,ref Point lastPntOfLine, ref int lastPntCounter, Pen pen, ref Point mLineEndPnt, Point mLineBeginPnt, Point location) { if (lastPntCounter == 0) { lastPntOfLine = location; lastPntCounter++; } else grfx.DrawLine(pen, mLineBeginPnt, lastPntOfLine); mLineEndPnt = location; Pen p = new Pen(Color.Black, 2); grfx.DrawLine(p, mLineBeginPnt, mLineEndPnt); lastPntOfLine = location; grfx.Dispose(); pen.Dispose(); p.Dispose(); }
what i made in this code is that i determine the last line drawen by nouse by getting its begin and end points from line object that i have then draw this line by background color to hide it and draw new line with black color to seen by user (this code is an alternative for using XOR mode, if any one know how to use it with drawing lines please tell me) thanks Generator -- modified at 4:12 Tuesday 8th May, 2007 -
hi all, i write this code to draw line by mouse and the drawline method is in the onPaint() method,this code is working properly but has two problems so is there any other idea to code it
private void mainScreen_MouseMove(object sender, MouseEventArgs e) { /// Determine the End point of the line if (lineFlag == 1 && !(mLineBeginPnt.IsEmpty) && nextLineFlag == 1) { Graphics grfx = this.CreateGraphics(); Pen pen = new Pen(mainScreen.DefaultBackColor, 2); userInterface.handleMouseMove(grfx, ref lastPntOfLine, ref lastPntCounter, pen, ref mLineEndPnt, mLineBeginPnt, e.Location); pen.Dispose(); grfx.Dispose(); Invalidate(drawingFrame); } } ---------------------------------------- public void handleMouseMove(Graphics grfx,ref Point lastPntOfLine, ref int lastPntCounter, Pen pen, ref Point mLineEndPnt, Point mLineBeginPnt, Point location) { if (lastPntCounter == 0) { lastPntOfLine = location; lastPntCounter++; } else grfx.DrawLine(pen, mLineBeginPnt, lastPntOfLine); mLineEndPnt = location; Pen p = new Pen(Color.Black, 2); grfx.DrawLine(p, mLineBeginPnt, mLineEndPnt); lastPntOfLine = location; grfx.Dispose(); pen.Dispose(); p.Dispose(); }
what i made in this code is that i determine the last line drawen by nouse by getting its begin and end points from line object that i have then draw this line by background color to hide it and draw new line with black color to seen by user (this code is an alternative for using XOR mode, if any one know how to use it with drawing lines please tell me) thanks Generator -- modified at 4:12 Tuesday 8th May, 2007HexaDeveloper wrote:
Graphics grfx = this.CreateGraphics();
You don't say what your problems are, but you should NEVER do this, unless you want to draw something that will immediately disappear. As soon as your window is obscured, your line will disappear, you should always draw your lines within the paint event of your form and call Invalidate() to force a paint event.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
HexaDeveloper wrote:
Graphics grfx = this.CreateGraphics();
You don't say what your problems are, but you should NEVER do this, unless you want to draw something that will immediately disappear. As soon as your window is obscured, your line will disappear, you should always draw your lines within the paint event of your form and call Invalidate() to force a paint event.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
hi , my problem is that i donot know how to use XOR mode in drawing line Generator