drawing in picturebox

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2006
Posts: 4
Reputation: lab3tech is an unknown quantity at this point 
Solved Threads: 0
lab3tech lab3tech is offline Offline
Newbie Poster

drawing in picturebox

 
0
  #1
Dec 5th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: drawing in picturebox

 
0
  #2
Dec 5th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: drawing in picturebox

 
0
  #3
Dec 5th, 2006
Hi,

Sorry in Above code make Y2 instead of Y3

Line1(1).Y2 =Y

REgards
Veena
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: drawing in picturebox

 
0
  #4
Dec 5th, 2006
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?
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 4
Reputation: lab3tech is an unknown quantity at this point 
Solved Threads: 0
lab3tech lab3tech is offline Offline
Newbie Poster

Re: drawing in picturebox

 
0
  #5
Dec 6th, 2006
Originally Posted by QVeen72 View Post
Hi,

Sorry in Above code make Y2 instead of Y3

Line1(1).Y2 =Y

REgards
Veena
Thank you so much - your code works beautifully!!
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 4
Reputation: lab3tech is an unknown quantity at this point 
Solved Threads: 0
lab3tech lab3tech is offline Offline
Newbie Poster

Re: drawing in picturebox

 
0
  #6
Dec 6th, 2006
Originally Posted by MattEvans View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: drawing in picturebox

 
0
  #7
Dec 6th, 2006
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.
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC