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

Recommended Answers

All 6 Replies

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

Hi,

Sorry in Above code make Y2 instead of Y3

Line1(1).Y2 =Y

REgards
Veena

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?

Hi,

Sorry in Above code make Y2 instead of Y3

Line1(1).Y2 =Y

REgards
Veena

Thank you so much - your code works beautifully!!

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.

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).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.