469,286 Members | 2,442 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,286 developers. It's quick & easy.

Using 2 instances of Line and PSet on same image?


I'm making a 'whiteboard' application.

I'm trying to have 2+ connected users able to draw at the same time.

However, if User1 draws a line, when User2 is drawing, on User1 screen,
it will draw another line, connecting User1's, and User2's current X,Y
position.
Same thing happens with User2.

But User3, and User4 is not drawing, and see the lines drawn individually.

I know the reason behind it. Although tough for me to explain.

Picture1_MouseDown uses the "Picture1.PSet (X,Y), Color"
Picture1_MouseMove uses the "Picture1.Line -(X,Y), Color"

I have tried every combinatin of Line, and PSet, none fixing my problem.

I'm sure if I used a transparent image, loaded into an Image Object,
I could assign a 'layer' to each connected user and PSet, and Line 'should'
work independantly from all other layers.

Is there -another- way around this, or am i stuck having to use the
transparent solution?


Jul 17 '05 #1
5 2540
> I'm making a 'whiteboard' application.

I'm trying to have 2+ connected users able to draw at the same time.

However, if User1 draws a line, when User2 is drawing, on User1 screen,
it will draw another line, connecting User1's, and User2's current X,Y
position.
Same thing happens with User2.

But User3, and User4 is not drawing, and see the lines drawn individually.

I know the reason behind it. Although tough for me to explain.

Picture1_MouseDown uses the "Picture1.PSet (X,Y), Color"
Picture1_MouseMove uses the "Picture1.Line -(X,Y), Color"

I have tried every combinatin of Line, and PSet, none fixing my problem.

I'm sure if I used a transparent image, loaded into an Image Object,
I could assign a 'layer' to each connected user and PSet, and Line 'should' work independantly from all other layers.

Is there -another- way around this, or am i stuck having to use the
transparent solution?


I'm not 100% sure I understand what you are trying to do, but let me guess.
I think the "structure" for a particular user (say identified as "1") should
be this

Dim LastX1 As Single
Dim LastY1 As Single
Dim Drawing1 As Boolean

Private Sub Picture1_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
LastX1 = X
LastY1 = Y
Drawing1 = True
End Sub

Private Sub Picture1_MouseMove(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
If Drawing1 Then
Picture1.Line (LastX1, LastY1)-(X, Y), Color
LastX1 = X
LastY1 = Y
End If
End Sub

Private Sub Picture1_MouseUp(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
Drawing1 = False
End Sub

That allows a user to start drawing anywhere within the PictureBox (while
the left-mousebutton is down). If you want to track other people doing
drawing, you can give them their own ID, duplicating the above for each. As
that would become cumbersome to code, I'd suggest using an array to identify
each person who is drawing. Maybe something like this (although I'm unclear
how multiple people are working in the program at one time):

Dim LastX() As Single
Dim LastY() As Single
Dim Drawing() As Boolean
Dim UserNumber As Integer

Private Sub Form_Load()
Dim NumberOfUsers
' Get the number of users by
' whatever means you are now using
NumberOfUsers = 3
ReDim LastX(1 To 3)
ReDim LastY(1 To 3)
ReDim Drawing(1 To 3)
' Elsewhere in code, identify the user
' who is drawing, again using whatever
' means you are now using
UserNumber = 2
End Sub

Private Sub Picture1_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
LastX(UserNumber) = X
LastY(UserNumber) = Y
Drawing(UserNumber) = True
End Sub

Private Sub Picture1_MouseMove(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
If Drawing1 Then
Picture1.Line (LastX(UserNumber), _
LastY(UserNumber))-(X, Y), vbRed
LastX(UserNumber) = X
LastY(UserNumber) = Y
End If
End Sub

Private Sub Picture1_MouseUp(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
Drawing(UserNumber) = False
End Sub

Hopefully, this is somewhere near the solution you are looking for.

Rick - MVP
Jul 17 '05 #2
> Private Sub Form_Load()
Dim NumberOfUsers
' Get the number of users by
' whatever means you are now using
NumberOfUsers = 3
ReDim LastX(1 To 3)
ReDim LastY(1 To 3)
ReDim Drawing(1 To 3)
' Elsewhere in code, identify the user
' who is drawing, again using whatever
' means you are now using
UserNumber = 2
End Sub


In the 2nd group of code I listed, I showed this Form_Load event. I used
that for testing purposes. The code listed in it would actually be executed
by you wherever in your program it makes sense to do so.

Rick - MVP
Jul 17 '05 #3
Yes, I know the question is not very clear.
And im not coming up w/ the right words to describe my problem

But I can get any/all users to draw.

The problem is, if User1 starts to draw a vertical line from top to
bottom of the left side of the Picture1, and User2 starts to draw
a vertical line from top to bottom on the right side of Picture1, both of
the
lines will draw fine, however, on User1, and User2 screen, horizontal lines
will appear connecting the two vertical lines at the X,Y position of User1/2

Any other users that are 'not' drawing, will see both vertical lines being
drawn fine.
No horizontal lines will be displayed.
But if they start drawing while someone else is, they will get them too.

If i wanted to draw at the same time, 2 horizontal lines down the sides of
a picture box, how would I do that? (not sure if this clears anything up or
not :c)

Do I have to 'queue' them?
Sorta Kinda Like the following...

Dim imDrawing As Boolean
Dim Color As Long
' Color gets assigned in the CommonDialog (Color) object

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

imDrawing = True ' Ok, You are drawing

' stop all other drawing on your
' Picture1 Box until MouseUp.

Picture1.PSet (X,Y), Color

End Sub

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

isDrawing = False

' We stopped drawing, so clear drawing queue
' so clear queue now

End Sub

Private Sub Winsock1_DataArrival(Index As Integer, _
ByVal bytesTotal As Long)

Dim sData As String
Winsock1(Index).GetData sData
' sData = "LINE:X ,Y, Color,DrawWidth

' insert code to pull out the fields here

If imDrawing = True Then
'
' Queue drawing requests here until MouseUp
'
Else
' We are not drawing, so go ahead and write the line
Picture1.DrawWidth = DrawWidth
Picture1.Line -(X,Y), Color
End If

End Sub
If you understand where Im going with the above...
It would still be an inconvenience, because you can't
see anyone else drawing while your drawing.
(however, id rather it be that way then no way at all)

Like I said, the unexpected lines that come up, are only seen
by the people drawing. Anyone -not- drawing see the lines as
they should be.

Confusing? Story of my life :c)

I'm not 100% sure I understand what you are trying to do, but let me guess. I think the "structure" for a particular user (say identified as "1") should be this

Dim LastX1 As Single
Dim LastY1 As Single
Dim Drawing1 As Boolean

Private Sub Picture1_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
LastX1 = X
LastY1 = Y
Drawing1 = True
End Sub

Private Sub Picture1_MouseMove(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
If Drawing1 Then
Picture1.Line (LastX1, LastY1)-(X, Y), Color
LastX1 = X
LastY1 = Y
End If
End Sub

Private Sub Picture1_MouseUp(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
Drawing1 = False
End Sub

That allows a user to start drawing anywhere within the PictureBox (while
the left-mousebutton is down). If you want to track other people doing
drawing, you can give them their own ID, duplicating the above for each. As that would become cumbersome to code, I'd suggest using an array to identify each person who is drawing. Maybe something like this (although I'm unclear how multiple people are working in the program at one time):

Dim LastX() As Single
Dim LastY() As Single
Dim Drawing() As Boolean
Dim UserNumber As Integer

Private Sub Form_Load()
Dim NumberOfUsers
' Get the number of users by
' whatever means you are now using
NumberOfUsers = 3
ReDim LastX(1 To 3)
ReDim LastY(1 To 3)
ReDim Drawing(1 To 3)
' Elsewhere in code, identify the user
' who is drawing, again using whatever
' means you are now using
UserNumber = 2
End Sub

Private Sub Picture1_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
LastX(UserNumber) = X
LastY(UserNumber) = Y
Drawing(UserNumber) = True
End Sub

Private Sub Picture1_MouseMove(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
If Drawing1 Then
Picture1.Line (LastX(UserNumber), _
LastY(UserNumber))-(X, Y), vbRed
LastX(UserNumber) = X
LastY(UserNumber) = Y
End If
End Sub

Private Sub Picture1_MouseUp(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
Drawing(UserNumber) = False
End Sub

Hopefully, this is somewhere near the solution you are looking for.

Rick - MVP

Jul 17 '05 #4
Rick's approach is right. After re-reading your original post, I realized that
the issue is where you said:

Picture1_MouseMove uses the "Picture1.Line -(X,Y), Color"

This draws a line from the "current position". Picture1 has only one current
position, even if two users are drawing, so you would be getting "cross" lines.
Something like Rick's structure, with separate LastX and LastY positions for
each user, should fix it up, without having to queue.

By the way, in a previous thread, it became pretty clear that using the
transparent property would not fix this sort of problem. Basically it seems that
you can't draw on a transparent background.

Just curious: have you checked that your network will allow your Winsock
connections? Many systems use firewalls to clamp down on which ports can be used
for connections.

"C. Alexander" <ca********@nospam.yahoo.com> wrote in message
news:u1*******************@fe3.columbus.rr.com...
Yes, I know the question is not very clear.
And im not coming up w/ the right words to describe my problem

But I can get any/all users to draw.

The problem is, if User1 starts to draw a vertical line from top to
bottom of the left side of the Picture1, and User2 starts to draw
a vertical line from top to bottom on the right side of Picture1, both of
the
lines will draw fine, however, on User1, and User2 screen, horizontal lines
will appear connecting the two vertical lines at the X,Y position of User1/2

Any other users that are 'not' drawing, will see both vertical lines being
drawn fine.
No horizontal lines will be displayed.
But if they start drawing while someone else is, they will get them too.

If i wanted to draw at the same time, 2 horizontal lines down the sides of
a picture box, how would I do that? (not sure if this clears anything up or
not :c)

Do I have to 'queue' them?
Sorta Kinda Like the following...

Dim imDrawing As Boolean
Dim Color As Long
' Color gets assigned in the CommonDialog (Color) object

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

imDrawing = True ' Ok, You are drawing

' stop all other drawing on your
' Picture1 Box until MouseUp.

Picture1.PSet (X,Y), Color

End Sub

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

isDrawing = False

' We stopped drawing, so clear drawing queue
' so clear queue now

End Sub

Private Sub Winsock1_DataArrival(Index As Integer, _
ByVal bytesTotal As Long)

Dim sData As String
Winsock1(Index).GetData sData
' sData = "LINE:X ,Y, Color,DrawWidth

' insert code to pull out the fields here

If imDrawing = True Then
'
' Queue drawing requests here until MouseUp
'
Else
' We are not drawing, so go ahead and write the line
Picture1.DrawWidth = DrawWidth
Picture1.Line -(X,Y), Color
End If

End Sub
If you understand where Im going with the above...
It would still be an inconvenience, because you can't
see anyone else drawing while your drawing.
(however, id rather it be that way then no way at all)

Like I said, the unexpected lines that come up, are only seen
by the people drawing. Anyone -not- drawing see the lines as
they should be.

Confusing? Story of my life :c)

I'm not 100% sure I understand what you are trying to do, but let me

guess.
I think the "structure" for a particular user (say identified as "1")

should
be this

Dim LastX1 As Single
Dim LastY1 As Single
Dim Drawing1 As Boolean

Private Sub Picture1_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
LastX1 = X
LastY1 = Y
Drawing1 = True
End Sub

Private Sub Picture1_MouseMove(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
If Drawing1 Then
Picture1.Line (LastX1, LastY1)-(X, Y), Color
LastX1 = X
LastY1 = Y
End If
End Sub

Private Sub Picture1_MouseUp(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
Drawing1 = False
End Sub

That allows a user to start drawing anywhere within the PictureBox (while
the left-mousebutton is down). If you want to track other people doing
drawing, you can give them their own ID, duplicating the above for each.

As
that would become cumbersome to code, I'd suggest using an array to

identify
each person who is drawing. Maybe something like this (although I'm

unclear
how multiple people are working in the program at one time):

Dim LastX() As Single
Dim LastY() As Single
Dim Drawing() As Boolean
Dim UserNumber As Integer

Private Sub Form_Load()
Dim NumberOfUsers
' Get the number of users by
' whatever means you are now using
NumberOfUsers = 3
ReDim LastX(1 To 3)
ReDim LastY(1 To 3)
ReDim Drawing(1 To 3)
' Elsewhere in code, identify the user
' who is drawing, again using whatever
' means you are now using
UserNumber = 2
End Sub

Private Sub Picture1_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
LastX(UserNumber) = X
LastY(UserNumber) = Y
Drawing(UserNumber) = True
End Sub

Private Sub Picture1_MouseMove(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
If Drawing1 Then
Picture1.Line (LastX(UserNumber), _
LastY(UserNumber))-(X, Y), vbRed
LastX(UserNumber) = X
LastY(UserNumber) = Y
End If
End Sub

Private Sub Picture1_MouseUp(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
Drawing(UserNumber) = False
End Sub

Hopefully, this is somewhere near the solution you are looking for.

Rick - MVP


Jul 17 '05 #5

I have been away so I have not been able to try out Ricks suggestion.
Will be testing tomorrow.

I have used Picture1.Line -(X,Y), Color as well as Picture1.PSet
(X,Y),Color and
Picture1.Line(X,Y)-(X,Y),Color without any hint of success.

Not sure what you are asking about winsock connections.
I haven't had any problems networking the application.

And thanks for the replies guys. I needed the help.

"Steve Gerrard" <no*************@comcast.net> wrote in message
news:mv********************@comcast.com...
Rick's approach is right. After re-reading your original post, I realized that the issue is where you said:

Picture1_MouseMove uses the "Picture1.Line -(X,Y), Color"

This draws a line from the "current position". Picture1 has only one current position, even if two users are drawing, so you would be getting "cross" lines. Something like Rick's structure, with separate LastX and LastY positions for each user, should fix it up, without having to queue.

By the way, in a previous thread, it became pretty clear that using the
transparent property would not fix this sort of problem. Basically it seems that you can't draw on a transparent background.

Just curious: have you checked that your network will allow your Winsock
connections? Many systems use firewalls to clamp down on which ports can be used for connections.

"C. Alexander" <ca********@nospam.yahoo.com> wrote in message
news:u1*******************@fe3.columbus.rr.com...
Yes, I know the question is not very clear.
And im not coming up w/ the right words to describe my problem

But I can get any/all users to draw.

The problem is, if User1 starts to draw a vertical line from top to
bottom of the left side of the Picture1, and User2 starts to draw
a vertical line from top to bottom on the right side of Picture1, both of the
lines will draw fine, however, on User1, and User2 screen, horizontal lines will appear connecting the two vertical lines at the X,Y position of User1/2
Any other users that are 'not' drawing, will see both vertical lines being drawn fine.
No horizontal lines will be displayed.
But if they start drawing while someone else is, they will get them too.

If i wanted to draw at the same time, 2 horizontal lines down the sides of a picture box, how would I do that? (not sure if this clears anything up or not :c)

Do I have to 'queue' them?
Sorta Kinda Like the following...

Dim imDrawing As Boolean
Dim Color As Long
' Color gets assigned in the CommonDialog (Color) object

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

imDrawing = True ' Ok, You are drawing

' stop all other drawing on your
' Picture1 Box until MouseUp.

Picture1.PSet (X,Y), Color

End Sub

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

isDrawing = False

' We stopped drawing, so clear drawing queue
' so clear queue now

End Sub

Private Sub Winsock1_DataArrival(Index As Integer, _
ByVal bytesTotal As Long)

Dim sData As String
Winsock1(Index).GetData sData
' sData = "LINE:X ,Y, Color,DrawWidth

' insert code to pull out the fields here

If imDrawing = True Then
'
' Queue drawing requests here until MouseUp
'
Else
' We are not drawing, so go ahead and write the line
Picture1.DrawWidth = DrawWidth
Picture1.Line -(X,Y), Color
End If

End Sub
If you understand where Im going with the above...
It would still be an inconvenience, because you can't
see anyone else drawing while your drawing.
(however, id rather it be that way then no way at all)

Like I said, the unexpected lines that come up, are only seen
by the people drawing. Anyone -not- drawing see the lines as
they should be.

Confusing? Story of my life :c)

I'm not 100% sure I understand what you are trying to do, but let me

guess.
I think the "structure" for a particular user (say identified as "1")

should
be this

Dim LastX1 As Single
Dim LastY1 As Single
Dim Drawing1 As Boolean

Private Sub Picture1_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
LastX1 = X
LastY1 = Y
Drawing1 = True
End Sub

Private Sub Picture1_MouseMove(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
If Drawing1 Then
Picture1.Line (LastX1, LastY1)-(X, Y), Color
LastX1 = X
LastY1 = Y
End If
End Sub

Private Sub Picture1_MouseUp(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
Drawing1 = False
End Sub

That allows a user to start drawing anywhere within the PictureBox (while the left-mousebutton is down). If you want to track other people doing
drawing, you can give them their own ID, duplicating the above for
each. As
that would become cumbersome to code, I'd suggest using an array to

identify
each person who is drawing. Maybe something like this (although I'm

unclear
how multiple people are working in the program at one time):

Dim LastX() As Single
Dim LastY() As Single
Dim Drawing() As Boolean
Dim UserNumber As Integer

Private Sub Form_Load()
Dim NumberOfUsers
' Get the number of users by
' whatever means you are now using
NumberOfUsers = 3
ReDim LastX(1 To 3)
ReDim LastY(1 To 3)
ReDim Drawing(1 To 3)
' Elsewhere in code, identify the user
' who is drawing, again using whatever
' means you are now using
UserNumber = 2
End Sub

Private Sub Picture1_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
LastX(UserNumber) = X
LastY(UserNumber) = Y
Drawing(UserNumber) = True
End Sub

Private Sub Picture1_MouseMove(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
If Drawing1 Then
Picture1.Line (LastX(UserNumber), _
LastY(UserNumber))-(X, Y), vbRed
LastX(UserNumber) = X
LastY(UserNumber) = Y
End If
End Sub

Private Sub Picture1_MouseUp(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
Drawing(UserNumber) = False
End Sub

Hopefully, this is somewhere near the solution you are looking for.

Rick - MVP



Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Aaron Prohaska | last post: by
3 posts views Thread by Sandeep Singh Sekhon | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.