944,044 Members | Top Members by Rank

Ad:
Dec 5th, 2006
0

drawing in picturebox

Expand Post »
I am a student, and have been working on a program where the user selects a drawing tool, color and line width then draws on a picturebox. I have the mouse coordinates of the picture box, and can draw the lines and rectangles I need. The drawings begin where the mouse button is pressed down and end when the mouse button is released. My problem is that the drawings do not appear until the mouse button is released. I want the drawings to be visible during the draw process. Is there a way I can do this?

Thank you in advance
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lab3tech is offline Offline
4 posts
since Nov 2006
Dec 5th, 2006
0

Re: drawing in picturebox

Hi,

Ok.. Yes u can do it. I will Give this For a Line Control.
Keep A Form Level Boolean Variable say LnFlag.

After Selecting Line From Ur Tool Box In Mouse Down of Picture Box,
Load a Line [Say Line1(1)] and Make the LnFlag =True and Make
Line1(1).X1 =X
Line1(1).Y1 =Y
Line1(1).X2 =X
Line1(1).Y3 =Y

In Picture1_MouseMove Event :

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If LnFlag Then
Line1(1).X2 = X
Line1(1).Y2 = Y
End If
End Sub

If MouseUp Event make
LnFlag =False

Similarly u can write for other Shapes.

I Hope It is clear.

Regards
Veena
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006
Dec 5th, 2006
0

Re: drawing in picturebox

Hi,

Sorry in Above code make Y2 instead of Y3

Line1(1).Y2 =Y

REgards
Veena
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006
Dec 5th, 2006
0

Re: drawing in picturebox

which event do you use to draw? and does your PictureBox use AutoRedraw or do you manually refresh it? and which version of VB are you using?
Moderator
Featured Poster
Reputation Points: 522
Solved Threads: 64
Veteran Poster
MattEvans is offline Offline
1,091 posts
since Jul 2006
Dec 6th, 2006
0

Re: drawing in picturebox

Click to Expand / Collapse  Quote originally posted by QVeen72 ...
Hi,

Sorry in Above code make Y2 instead of Y3

Line1(1).Y2 =Y

REgards
Veena
Thank you so much - your code works beautifully!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lab3tech is offline Offline
4 posts
since Nov 2006
Dec 6th, 2006
0

Re: drawing in picturebox

Click to Expand / Collapse  Quote originally posted by MattEvans ...
which event do you use to draw? and does your PictureBox use AutoRedraw or do you manually refresh it? and which version of VB are you using?

I use the mouse events to draw and I manually refresh. I am using VB 2003.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lab3tech is offline Offline
4 posts
since Nov 2006
Dec 6th, 2006
0

Re: drawing in picturebox

oooh.. 2003. i've only ever used VB6.

in VB6 there are lots of mouse events (mousemove,mouseup,mousedown,click). usually i use the mousemove event for "drawing" > set a flag "drawing" to true, and while "drawing" is true, draw a line between where the mouse was and where the mouse is; so, similar to QVeen72's idea :- but I'd draw directly to the surface rather than place a line object. check out the lineto() and moveto() API functions..

http://edais.mvps.org/Tutorials/Graphics/GFXch7.html

there may be native "line() or drawLine()" function in a picturebox control (or maybe on a device context if VB2003 has that concept yet).
Last edited by MattEvans; Dec 6th, 2006 at 4:03 am.
Moderator
Featured Poster
Reputation Points: 522
Solved Threads: 64
Veteran Poster
MattEvans is offline Offline
1,091 posts
since Jul 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Please help me-- from shaji
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Reading a Binary file using Visual Basic





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC