简体   繁体   English

仅形式的不透明度

[英]Form-only opacity

First I'm going to show you an image of what I'm trying to recreate in pure NET. 首先,我将向您展示我试图在纯NET中重新创建的图像。

Image 图片

I recreated the window "Inventory" ,the only thing left is the blue-opacity window ,which shows information. 我重新创建了“库存”窗口,剩下的只有蓝色不透明窗口,它显示信息。

If I use the opacity property then everything on that form has opacity,but on the picture the text doesn't have opacity. 如果我使用opacity属性,则该表单上的所有内容都具有不透明度,但是在图片上文本没有不透明度。

How do I make the opacity only on the form? 如何仅在表单上设置不透明度?

The Opacity property only exists on the form so there's no way it could be overridden on the controls contained therein. Opacity属性仅存在于表单上,因此无法在其中包含的控件上覆盖它。

I did think that a slightly transparent background image might give the effect you wanted - but I've just tried it and it didn't seem to work. 我确实认为稍微透明的背景图像可能会提供您想要的效果-但我已经尝试过了,但似乎没有效果。

Not sure if this helps but the only thing I can think of short of using WPF would be to use TransparencyKey and backcolor of the form. 不确定这是否有帮助,但是我唯一想到的就是使用TransparencyKey和表单的背景色,这是我使用WPF的唯一不足。 Just make sure your TransparencyKey is not set as default control or gray, may the backcolor of the form red or something. 只要确保您的TransparencyKey未被设置为默认控件或灰色,可能是红色或其他形式的背景色即可。 If your looking for partial transparency you might end up having to use WPF. 如果您希望部分透明,则最终可能不得不使用WPF。 Personally I've never tried opacity with WPF on an actual form so you "may" get the same results but... 就我个人而言,我从未尝试过以实际形式使用WPF进行不透明度,因此您“可能”获得相同的结果,但是...

EDIT: WPF causes the same condition. 编辑:WPF导致相同的情况。 All controls under the form become transparent with the form. 表单下的所有控件对表单都是透明的。 Probably because they inherent the forms properties. 可能是因为它们固有的形式属性。

you can use this: 您可以使用此:

    using System.Drawing.Drawing2D;

    private void Form1_Paint(object sender, PaintEventArgs e)
    {
        var hb = new HatchBrush(HatchStyle.Percent50, this.TransparencyKey);

        e.Graphics.FillRectangle(hb, this.DisplayRectangle);
    }

wait help you.. bye 等待帮助你..再见

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

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