How to draw string or line in Picturebox?

HolySanta
06-22-2006, 05:09 AM
Hi guys, I know this is a noob question coz I can't find any threat that can help me in this.

I had a picture box that I want to draw a ruler on it. I try something like the code below but it just can't works. The picturebox did not show any thing.

'This is to draw the line
picRuler.CreateGraphics.DrawLine(Pens.Black, 0, 0, 0, 5)
'This is to draw the string
picRuler.CreateGraphics.DrawString("Inches", myFont, 0, 0)

Maybe I left something out coz I when I tried to use form's creategraphics object, nothing come out in the font as well.

Please help.

JNewt
06-22-2006, 10:25 AM
You need to redraw every time the picturebox repaints. The best way to do this is place your drawing code in the Paint event of the picturebox and use the graphics object that is passed to you (e.Graphics).

HolySanta
06-22-2006, 12:00 PM
You need to redraw every time the picturebox repaints. The best way to do this is place your drawing code in the Paint event of the picturebox and use the graphics object that is passed to you (e.Graphics).

Thanks JNewt. Everything going smoothly. But one question, if I have a run-time drawing, like when user click a button and the picturebox will draw something, we need to redraw right? but how do we call the redraw event?

JNewt
06-22-2006, 12:23 PM
To tell a control to repaint you simply need to use the Invalidate method of the control (in this case the picturebox).

HolySanta
06-22-2006, 01:09 PM
Thanks a lot JNewt. It really helps.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum