简体   繁体   English

PictureBox(面板上)上的C#标签(透明backGround)

[英]C# Label(Transparent backGround) on PictureBox (on Panel)

I want to draw the Labels on PictureBoxes but should be transparent background . 我想在PictureBoxes上绘制标签,但是应该是透明背景。 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 . 我正在画我的图片,标签也很好。。。但是我在图片下面得到了标签(当我将图片拖出他的位置时,我可以看到每个标签),所以我想知道如何将它们放在正面与透明BackGround。 thank you ` 谢谢你

我认为您应该使用像z-index这样的东西

Try calling Panels.Controls[Labels[i].Name].BringToFront(); 尝试调用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. 这将使每个标签位于图片的前面,因为此时已将它们添加到面板中。

I suppose you've already googled for this but here's a good link about winforms transparency . 我想您已经在Google上进行了搜索,但这是有关Winforms透明性的一个很好的链接

I used to write many winforms applications that used very ugly skins with transparent labels. 我曾经编写过许多使用带有透明标签的难看皮肤的winforms应用程序。 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. 我记得在将jpg用作背景图片时以及在绘制标签加载图片时会出现一些故障。

Anyway, I suggest overriding onPaint and onDraw methods as you can see in the link. 无论如何,我建议重写onPaint和onDraw方法,如您在链接中所见。

Transparency is only with respect to the container. 透明度仅针对容器。 For this to work you have to add the Label to the PictureBox . 为此,您必须将Label添加到PictureBox Change Panels to the name of the PictureBox you are working with in the Controls.Add() line. Controls.Add()行中将Panels更改为正在使用的PictureBox的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM