Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Drawing line in running time [modified]

Drawing line in running time [modified]

Scheduled Pinned Locked Moved C#
graphicstutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HexaDeveloper
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • H HexaDeveloper

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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 )

      H 1 Reply Last reply
      0
      • C Christian Graus

        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 )

        H Offline
        H Offline
        HexaDeveloper
        wrote on last edited by
        #3

        hi , my problem is that i donot know how to use XOR mode in drawing line Generator

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups