Results 1 to 4 of 4

Thread: XOR Drawing

  1. #1

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    XOR Drawing

    Remember in VB6 when you could set a picturebox's drawmode to XOR, then if you draw a line and then draw it again, the line would dissapear?

    How can this be achieved in .Net without having to refresh the entire picturebox area?

    I need to be able to drag a line using the mouse and I need rapid responding code without flicker.

    How is it done?

    Help!
    I don't live here any more.

  2. #2
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    You can't do it, using normal GDI+.
    But you can use the ControlPaint object.
    There's a method to draw a reversible line.

    Problem is, that it draws to the screen DC and not a normal graphics object, so you have to clip your mouse to stay within the borders of your picturebox.

    Also, if the picturebox is refreshed the line disappears.

    I you're talking about a rubberband, then none of this should really be a problem, as long as you clip your mouse.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  3. #3
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    Try this code:
    VB Code:
    1. Dim OldLineStart As Point
    2.     Dim OldLineEnd As Point
    3.  
    4.     Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
    5.         Dim R As Rectangle = PictureBox1.ClientRectangle
    6.         R.Offset(PictureBox1.PointToScreen(PictureBox1.ClientRectangle.Location))
    7.         Cursor.Clip = R
    8.         OldLineStart = PictureBox1.PointToScreen(New Point(e.X, e.Y))
    9.         OldLineEnd = OldLineStart
    10.     End Sub
    11.  
    12.     Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
    13.         Cursor.Clip = Nothing
    14.         PictureBox1.Invalidate()
    15.     End Sub
    16.  
    17.     Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
    18.         If e.Button = MouseButtons.Left Then
    19.             ControlPaint.DrawReversibleLine(OldLineStart, OldLineEnd, PictureBox1.BackColor)
    20.             OldLineEnd = PictureBox1.PointToScreen(New Point(e.X, e.Y))
    21.             ControlPaint.DrawReversibleLine(OldLineStart, OldLineEnd, PictureBox1.BackColor)
    22.         End If
    23.     End Sub
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  4. #4

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Ok, I'll just have to do the math myself with setpixel() and so on.
    Last edited by wossname; Mar 5th, 2004 at 04:25 AM.
    I don't live here any more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width