0

I want to draw the Labels on PictureBoxes but should be transparent background . This is my code : `

                           Labels[i].Location = new Point(0, 0);
                            Labels[i].Size = new Size(13, 13);
                            Labels[i].BackColor = Color.Transparent;
                            Labels[i].ForeColor = Color.Blue;


  Invoke(new MethodInvoker(delegate { Panels.Controls.Add(Pictures[i]); }));
                                    Invoke(new MethodInvoker(delegate { Panels.Controls.Add(Labels[i]); }));

I'am drawing my Pictures fine, Labels too ... But I get the Labels under the Pictures (I can see each label when I drag the Picture out of his place) so I want to know , how I can put them in Front with Transparent BackGround . thank you `

Hacking Games
  • 63
  • 1
  • 5
  • 14

4 Answers4

0

i think you should use something like z-index

Romko
  • 1,808
  • 21
  • 27
0

Try calling Panels.Controls[Labels[i].Name].BringToFront(); in your delegate. This should bring each label in front of the pictures since they've already been added to the panel at that point.

ramsey_tm
  • 792
  • 5
  • 7
  • It does bring them ... but won't get Transparent BackGround as should be . – Hacking Games Oct 07 '13 at 14:06
  • I assume you are using winforms yes? In that case changing a BackColor will not work. There are work arounds but it is not possible in winforms by default, perhaps you'd be better off using WPF. Take a look at an old but relevant thread with workaround for transparency here: http://stackoverflow.com/questions/4639482/how-to-do-a-background-for-a-label-will-be-without-color – ramsey_tm Oct 07 '13 at 14:10
  • Well I need this in WinForms – Hacking Games Oct 07 '13 at 14:15
  • Then you'll have to research some of the work-arounds listed in my previous comment. – ramsey_tm Oct 07 '13 at 14:21
0

I suppose you've already googled for this but here's a good link about winforms transparency.

I used to write many winforms applications that used very ugly skins with transparent labels. As I can remember there was some glitches when used jpg as a background picture and if picture loaded after the label has been drawn.

Anyway, I suggest overriding onPaint and onDraw methods as you can see in the link.

Perrier
  • 2,753
  • 5
  • 33
  • 53
0

Transparency is only with respect to the container. For this to work you have to add the Label to the PictureBox. Change Panels to the name of the PictureBox you are working with in the Controls.Add() line.

Idle_Mind
  • 38,363
  • 3
  • 29
  • 40