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. XOR problem

XOR problem

Scheduled Pinned Locked Moved C#
graphicshelp
5 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, this is my problem i used this code Graphics grfx = this.createGraphics(); grfx.DrawLine(Pens.Black,p1,p2); in the Mouse_Move EventHandler but it draw alot of lines so i want to use XOR mode to draw only the last one thanx in advance Generator

    M 1 Reply Last reply
    0
    • H HexaDeveloper

      hi all, this is my problem i used this code Graphics grfx = this.createGraphics(); grfx.DrawLine(Pens.Black,p1,p2); in the Mouse_Move EventHandler but it draw alot of lines so i want to use XOR mode to draw only the last one thanx in advance Generator

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      Hi! You could use ControlPaint.DrawReversibleLine() to get something like an "XOR" mode. But are you sure you know what you're doing? Usually creating a graphics object in a mouse event handler to do some painting is a bad idea. Do you dispose of every Graphics object you create? Beginners usually forget about it and then get ressource leaks. And what if the surface you're drawing your lines on gets hidden by another window and redrawn? All your lines will be gone...

      Regards, mav -- Black holes are the places where God divided by 0...

      H 1 Reply Last reply
      0
      • M mav northwind

        Hi! You could use ControlPaint.DrawReversibleLine() to get something like an "XOR" mode. But are you sure you know what you're doing? Usually creating a graphics object in a mouse event handler to do some painting is a bad idea. Do you dispose of every Graphics object you create? Beginners usually forget about it and then get ressource leaks. And what if the surface you're drawing your lines on gets hidden by another window and redrawn? All your lines will be gone...

        Regards, mav -- Black holes are the places where God divided by 0...

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

        hi mav, actually i didnot draw in mouse move i put every drawing in OnPaint() but it make some problems in other parts of code so i decided to draw it in mouse move (iam just trying to solve my problem so i didnot think in Dispose) and thanx for remembering me of Dispose as i think u solve to me the problem of my program stop(Resources leak) thanx again(i will try ControlPaint.DrawReversibleLine()) Generator

        H 1 Reply Last reply
        0
        • H HexaDeveloper

          hi mav, actually i didnot draw in mouse move i put every drawing in OnPaint() but it make some problems in other parts of code so i decided to draw it in mouse move (iam just trying to solve my problem so i didnot think in Dispose) and thanx for remembering me of Dispose as i think u solve to me the problem of my program stop(Resources leak) thanx again(i will try ControlPaint.DrawReversibleLine()) Generator

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

          hi mav, i read about ControlPaint.DrawReversibleLine in MSDN and if my understanding(it deletes the first draw if drawen again by same coordinates) is right so i think it will not be true to use it as i tried it and nothing changed thanx Generator

          H 1 Reply Last reply
          0
          • H HexaDeveloper

            hi mav, i read about ControlPaint.DrawReversibleLine in MSDN and if my understanding(it deletes the first draw if drawen again by same coordinates) is right so i think it will not be true to use it as i tried it and nothing changed thanx Generator

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

            Hi mav, thanx for ur efforts but i think i made actually not good solution but i think it work at this time this is the code(please tell me if any notes) Graphics grfx = this.CreateGraphics(); Pen pen = new Pen(mainScreen.DefaultBackColor); if (counter == 0) { lastPntOfLine = e.Location; counter++; } else grfx.DrawLine(pen, mLineBeginPnt, lastPntOfLine); mLineEndPnt = e.Location; grfx.DrawLine(Pens.Black, mLineBeginPnt, mLineEndPnt); lastPntOfLine = e.Location; grfx.Dispose(); pen.Dispose(); Invalidate(); i felt very stubid to write that but this is my thinking until now 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