Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pset Issue? 1

Status
Not open for further replies.

wraygun

Programmer
Dec 9, 2001
272
US
I'm playing around with making a primitive drawing utility as a supplement for one of my apps. To draw in a picturebox is pretty straightforword, however if the cursor moves too fast there is a space between the pixels. Does any know an easy way to 'automatically' connect the pixels if the users moves the mouse too quickly?

Here is an excerpt from my code:

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Button = 1 Then Picture1.PSet (X, Y)

End Sub

Thanks in advance,
The Gun
 
You can try "pset-ing" all around the pixel so it makes a thicker line. I'm not sure how big your "gaps" are, but this should work .. (in theory).

Like:
If Button = 1 Then

Picture1.PSet (X, Y)
Picture1.PSet (X, Y+1)
Picture1.PSet (X, Y-1)
Picture1.PSet (X+1, Y)
Picture1.PSet (X-1, Y)
Picture1.PSet (X+1, Y+1)
Picture1.PSet (X-1, Y-1)
Picture1.PSet (X+1, Y-1)
Picture1.PSet (X-1, Y+1)

end if
 
MouseMove is wierd like that, you can never be sure how many times Windows will call it for you. If the mouse is moved 100 pixels, it could be called anywhere between 1 and 100 times depending on the environment. What I would do is keep track of the last X and Y coordinates and draw a line to connect the dots if the button is still down:

--------------------------
Option Explicit

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static LastX As Integer
Static LastY As Integer

If Button = 1 And LastX > 0 Then
Picture1.Line (LastX, LastY)-(X, Y)
End If

If Button = 1 Then
Picture1.PSet (X, Y)
LastX = X
LastY = Y
Else
' User is drawing a new line, don't connect
LastX = -100
LastY = -100
End If

End Sub
--------------------------------

Good luck!

~Mike
Now and then it's good to pause in our
pursuit of happiness and just be happy.

- Guillaume Apollinaire
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top