01-18-2005, 08:00 AM
I'm trying to do a repeat drawing program using a selection of picture boxes.
I have a grid of 3*3 picture boxes and would like that when I draw across any of them it is repeated in all the others.
I've got this bit working, but the when the mouse makes the transition from picture box to another, it looses the ability to draw.
I use the standard press and hold the mouse button down to draw method.
I've attached code of what I've done (execute the project and tick the check box then draw).
Any assistance appreciated.
01-18-2005, 09:18 PM
Well, I think you will always have some tricky transition issues to take care of.
Even if you moved the mouse focus to another picturebox, what will happen when you
draw a line from the old coordinates to the new cooridnates?
For instance, say we start in the middle of a box, and move to the left.
Our line follows the mouse till it reaches an X of 0.
Our next movement to the left will bring us to the right edge of a new box, let's say
the right edge had an X of 100. So we draw our line from a X= 0 to to X = 100
resulting in a horizontal line being drawn straight across all nine boxes.
You would have the same problem with the Y and vertical lines as you moved from the
end of one scale to the begining of the other.
But, if you want to see it for yourself, add some code to add an offset of 3 box widths
or heights to your X and Y (since you have a 3x3 arrangement), and then use the Mod
function to limit that value to the range of of 1 box's height and width.
Then use that value in your drawing.
Here's a modification to your code that does that.
After you see the horizontal and vertical line streaks
uncomment the " 'passel " code lines, to add code that checks for jumps in the
coordinates of more than 1/2 a box width, which will eliminate the streaks, but will
leave small gaps at the edges of where the boxes meet.
It would be a bit of a challenge to try and close those gaps smoothly.
Another possible implementation would be to just use a fullsize picturebox and calculate
the eight other offsets mathematically, and draw the 9 lines in the one box
rather than one line in 9 boxes.
Private Sub pic1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim intloop As Integer
If blnDraw Then
'xt and yt will be calculated by adding large offset (multiples of the box sizes)
'so that X and Y mouse coordinates that go negative when the mouse is dragged
'to the left or above a box will be converted to positive values.
'a mod function is then used to adjust the values to the normal range
'which will also handle when the mouse is dragged to the right or below
'the original starting picturebox
xt = (X + 3 * pic1(0).ScaleWidth) Mod pic1(0).ScaleWidth
yt = (Y + 3 * pic1(0).ScaleHeight) Mod pic1(0).ScaleHeight
'passel If Abs(xt - intXStart) > pic1(0).ScaleWidth / 2 Or _
'passel Abs(yt - intYStart) > pic1(0).ScaleHeight / 2 Then
'passel intXStart = xt
'passel intYStart = yt
'passel End If
pic1(0).AutoRedraw = True
pic1(0).Line (intXStart, intYStart)-(xt, yt), QBColor(0)
If blnRepeatON Then
For intloop = 1 To 8
pic1(intloop).AutoRedraw = True
pic1(intloop).Line (intXStart, intYStart)-(xt, yt), QBColor(0)
' intXStart = X
' intYStart = Y
pic1(intloop).AutoRedraw = False
intXStart = xt
intYStart = yt
pic1(0).AutoRedraw = False
01-19-2005, 01:16 AM
Thanks for that Passel.
Thats almost exactly what I want to do.
The idea is for drawing "tiles" (for want of a better word) that will seamlessly match when placed side by side, hence the 3*3 format to see the repeats for the centre "tile".
I'll have a play on what you've done to see if I can, make it work.
Thanks again for your help.