Border around a ContainerControl - it's been driving me MAD!

kingballz

New member
Joined
Jan 13, 2011
Messages
4
Programming Experience
3-5
Hi guys, sorry if this is an easy question (and yes, I've just spent 5 hours looking for a solution on google with no joy)

Basically I have a form, on the form is a number of container controls, each containing a number of picture boxes. Any way, all I'm trying to do is find some way of getting a colored border around each one of the container controls. I find the graphics coding in vb.net to be beyond me - could anybody tell me how this is done or an easier way to do it?

Thanks so much in advance!
 
You handle the Paint event of the control and e.Graphics.DrawRectangle. You will need to specify a Rectangle of the appropriate size based on the size of the control. You may need to adjust things a bit to prevent pixels being drawn outside the bounds of the control but a bit of trial and error should get you there.
 
Thanks for the reply - so at least I know where I should be looking - the controlcollection paint event...the problem is I have no clue about pens and graphics and all the rest . Sorry for putting you out but is there any chance you could show me a few lines of code to get it started? Thanks again :smile:
 
No, not the ControlCollection Paint event. There is no such event. The Paint event of the control you want to draw on, e.g. if you want a border on a Panel then you handle the Paint event of that Panel.

You already have the Graphics object provided by the event handler. As for the Pen, you simply invoke the class constructor and specify the Color and Width of the line. If you want a Width of 1 then you can even use the Pens class to get a pre-existing Pen by Color.
 
Back
Top