Lines in Picture Box

No matter how I try, I can't get a line shape to show on top of a picture box. When I drag the shape onto the control, it shows, but immediately upon release it goes behing. I have several pictureboxes, and simply telling them to go to the back does not work as they have to be at different levels... I've tried to set the top one to the back, first, then the next and the next to try to get them in order, but the line shape still goes to the back. If only there was a right click on them to adjust the %^&&#*$ order.
[529 byte] By [berick] at [2008-1-10]
# 1

The line and shape controls are designed, just like their VB6 predecessors, to be at the bottom of the z-order.

If you which to draw a line on a picture box you could do this at runtime with code similar to the following example that draws an orange line horizontally across the middle of a picturebox control:

Dim intY As Integer = PictureBox1.Height / 2

PictureBox1.CreateGraphics.DrawLine(Pens.Orange, PictureBox1.ClientRectangle.Left, intY, PictureBox1.ClientRectangle.Right, intY)

JohnHart_MSFT at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic Power Packs...
# 2

Thanks, now how to erase.

I am using a verticle line that moves across the picturebox, but using your example, I would delay a little, and try to erase the line. But inplace of Pens.Orange, I would want to use the Picturebox1.BackColor . How does one convert that to a pens color or something legal in the first parameter of DrawLine?

Barry

berick at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic Power Packs...
# 3

To use the same color as the PictureBox.BackColor all you need to do is create a new pen.

For example:

Dim intY As Integer = PictureBox1.Height / 2

Dim p As New System.Drawing.Pen(PictureBox1.BackColor)

PictureBox1.CreateGraphics.DrawLine(p, PictureBox1.ClientRectangle.Left, intY, PictureBox1.ClientRectangle.Right, intY)

To remove the line simply call:

PictureBox1.Refresh

JohnHart_MSFT at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic Power Packs...