|
-
Mar 5th, 2004, 03:09 AM
#1
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.
-
Mar 5th, 2004, 04:10 AM
#2
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...
-
Mar 5th, 2004, 04:20 AM
#3
Hi.
Try this code:
VB Code:
Dim OldLineStart As Point
Dim OldLineEnd As Point
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
Dim R As Rectangle = PictureBox1.ClientRectangle
R.Offset(PictureBox1.PointToScreen(PictureBox1.ClientRectangle.Location))
Cursor.Clip = R
OldLineStart = PictureBox1.PointToScreen(New Point(e.X, e.Y))
OldLineEnd = OldLineStart
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
Cursor.Clip = Nothing
PictureBox1.Invalidate()
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If e.Button = MouseButtons.Left Then
ControlPaint.DrawReversibleLine(OldLineStart, OldLineEnd, PictureBox1.BackColor)
OldLineEnd = PictureBox1.PointToScreen(New Point(e.X, e.Y))
ControlPaint.DrawReversibleLine(OldLineStart, OldLineEnd, PictureBox1.BackColor)
End If
End Sub
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Mar 5th, 2004, 04:21 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|