Search code examples
c#winformstransparency

semi-transparent form but opaque Controls in C#


How to make semi transparent form in C# windows form application

I have tried the TransparentKey which makes it full-transparent. and tried Opacity but it effects the whole form (with controls).

I want only form part to be semi-transparent but not Controls.


Solution

  • You can use a hatch brush with a certain percentage, for example:

        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);
        }