Showing posts from July, 2016

Draw transparent Label on PictureBox C#.NET

Label control supports transparent property but picture box do not work as container control. So even if we add label control on picturebox the parent control will become main form or any other underlying container control. Hence on adding label control on picture box and making label control background  transparent shows background of form or any other container control is rather than picture box.

This can be changed using simple code in form constructor. We need to change parent property of label and recalculate its location because it is now relative to picturebox instead of form. Hetre is the sample code to do this -

 public Form1() {
        var pos = this.PointToScreen(label1.Location);
        pos = pictureBox1.PointToClient(pos);
        label1.Parent = pictureBox1;
        label1.Location = pos;
        label1.BackColor = Color.Transparent;