在.NET透明的用户控制透明、用户、NET

2023-09-07 09:34:02 作者:两不疑.

我试图使Web风格的按钮,用户可以控制。我需要让用户控件的背景透明。如何做到这一点,而不进行控制看不见的。此外,我还需要透明的标签和图片框。

试图让这样的事情:

  this.SetStyle(ControlStyles.SupportsTransparentBackColor,真正的);
this.BackColor = Color.Transparent;
 

解决方案

这三个控制你列出已经有ControlStyles.SupportsTransparentBackColor风格开启。刚刚成立的设计师,网页标签的背景色属性。它的非常的原因尚不清楚,这不是配不上你。

这是另有一种错觉,Windows窗体通过询问家​​长控件绘制自身在OnPaintBackground()方法,因此提供了背景像素实现它。一个值得注意的事情,不工作是重叠的控制。你只看到家长像素,重叠的控制,而不是像素。这是可以解决的,但code是的fugly。

唯一的其他透明度选项Form.TransparencyKey。这是真正的透明,通过使用叠加在视频适配器实现。问题是,这仅适用于顶层窗口。形式,而不是控制。

这些限制是固有的Windows窗体渲染模型,使用各个窗口的控制。 Web浏览器不具有相同的限制,它通过绘制它们模拟控制。油漆层,这使得透明度琐碎的,只需不画。 WPF使用的渲染模式也是如此。

如何在.NET Core Web App中管理用户机密数据管理

I'm trying to make a web style button with user control. I need to make User Control's background transparent. How to do this without making controls invisible. Also I'll need transparent Label and PictureBox.

Trying to make something like this:

this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.BackColor = Color.Transparent;

解决方案

All three controls you list already have the ControlStyles.SupportsTransparentBackColor style turned on. Just set the BackColor property in the designer, Web tab. It is very unclear why that's not good enough for you.

It is otherwise an illusion, Windows Forms implements it by asking the Parent control to draw itself in the OnPaintBackground() method so it provides the background pixels. One notable thing that doesn't work is overlapping controls. You only see the Parent pixels, not the pixels of the overlapped control. That's fixable but the code is fugly.

The only other transparency option is Form.TransparencyKey. That's true transparency, implemented by using overlays in the video adapter. Problem is that this only works on toplevel windows. Forms, not controls.

These restrictions are inherent in the Windows Forms rendering model, using individual windows for the controls. A web browser doesn't have that same restriction, it emulates controls by drawing them. Layers of paint, that makes transparency trivial by just not painting. WPF uses that rendering model as well.

 
精彩推荐
图片推荐