wael gg

wael gg

  • NA
  • 6
  • 0

drawing line in the run

May 8 2007 4:20 AM

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