简体   繁体   中英

Form-only opacity

First I'm going to show you an image of what I'm trying to recreate in pure 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.

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.

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. Just make sure your TransparencyKey is not set as default control or gray, may the backcolor of the form red or something. If your looking for partial transparency you might end up having to use WPF. Personally I've never tried opacity with WPF on an actual form so you "may" get the same results but...

EDIT: WPF causes the same condition. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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