 |

03-08-2005, 01:33 AM
|
 |
fully realized avatar
Super Moderator * Expert *
|
|
Join Date: Jun 2004
Location: Davao Philippines
Posts: 2,295
|
|
Rubberband like feature in a picture box
|
Hello Guys,
Im want to create a line by clicking two points on a picturebox. I would like to obtain a rubberbanding feature where a line is drawn tailing the mouse pointer after the first point is selected and until the second point is selected.
There are several lines already drawn in my picturebox. I saved the attributes of these lines via UDT.
My first move in obtaining this rubberbanding feature is I used the CLS method and loop through all the items in my UDT and draw them one by one during MouseMove event.
This works nicely, but the picture box flickers a lot while the loop is on going.
Is there a better way of obtaining a rubberband like feature without the flicker?
Is there a picture box property like a Redraw = False which eliminates flicker?
Thanks! 
|
|

03-08-2005, 04:26 AM
|
|
Regular
|
|
Join Date: Mar 2004
Posts: 50
|
|
I am using this and it's not flickering.
Let's say that firstx is the first x-point and firsty is the y-point, and line contains wiether or not your going to draw the line
Code:
Dim line as Boolean
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
line = True
firstx = X
firsty = Y
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If line = True Then
Picture1.Cls
Picture1.Line (firstx, firsty)-(X,Y)
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If line = True Then
Picture1.Cls
Picture1.Line (firstx, firsty)-(X,Y)
line = False
End Sub
Picture1.AutoRedraw = True
I dosen't know if that would help you but i hope so. GLHF 
|
|

03-08-2005, 04:57 AM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
|
A simpler way would be to just draw your rubber band box using the NOT XOR operation. This eliminates the need to cls your picturebox since the NOT XOR operation can be used to erase the old box.
|
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Last edited by BillSoo; 03-08-2005 at 05:11 AM.
|

03-08-2005, 05:11 AM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
Here is some example code with a picturebox on a form:
Code:
Option Explicit
Dim StartX As Single
Dim StartY As Single
Dim LastX As Single
Dim LastY As Single
Dim oldMode As Integer
Private Sub Form_Load()
Dim i As Integer
Dim mx As Integer
Dim my As Integer
Picture1.ScaleMode = vbPixels
Picture1.AutoRedraw = True
mx = Picture1.ScaleWidth
my = Picture1.ScaleHeight
For i = 1 To 30
Picture1.Line (Rnd() * mx, Rnd() * my)-(Rnd() * mx, Rnd() * my)
Next i
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
StartX = X
LastX = X
StartY = Y
LastY = Y
oldMode = Picture1.DrawMode
Picture1.DrawMode = 10 'not xor pen
Picture1.Line (StartX, StartY)-(LastX, LastY)
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button Then
Picture1.Line (StartX, StartY)-(LastX, LastY)
LastX = X
LastY = Y
Picture1.Line (StartX, StartY)-(LastX, LastY)
End If
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.Line (StartX, StartY)-(LastX, LastY)
Picture1.DrawMode = oldMode
End Sub
|
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|