0

I would like to make an entire Control and its children have a see-through effect so that it looks disabled.

My Control was initially a UserControl but trying to change the alpha on the BackColor yielded an exception so I made it a Form instead.

I have tried the methods outlined in my code but the form just doesn't want to become transparent.

Microsoft's documentation stated: "The Opacity property enables you to specify a level of transparency for the form and its controls."

Source: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.form.opacity

This is what had led me to believe making the form and its child controls transparent is a possibility.

MyTransparentWindow has some text fields and buttons on it in the designer.

public partial class frmMain : Form {
        public frmMain()
        {
            InitializeComponent();

            instance = this;
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
             this.Controls.Add(new MyTransparentWindow());
        }
}

public partial class MyTransparentWindow : Form {
    public MyTransparentWindow()
    {
            InitializeComponent();
            
            this.TopLevel = false;
            this.FormBorderStyle = FormBorderStyle.None;
            this.ControlBox = false;
            this.ShowInTaskbar = false;
            this.StartPosition = FormStartPosition.Manual;
            this.AutoScaleMode = AutoScaleMode.None;
            
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.BackColor = Color.Transparent;

            this.Opacity = 0.5;
        }
}
  • 2
    You see, back in the olden-days, Microsoft never really designed WinForms for a rich UI experience, it wasn't really the idea of windows, they envisaged a pedestrian interface where everything conformed to a certain predictable standard. Sounds like you want to update your framework to something which has a rich UI and customization built-in from the ground up and optimised for, like WPF, or UWP. – TheGeneral Oct 13 '20 at 03:26
  • https://stackoverflow.com/questions/5064774/opacity-on-control – TheGeneral Oct 13 '20 at 03:32
  • Yes, quite sad. I WinForms seems messy internally, setting some properties when they arent supported will throw an exception, while other unsupported properties don't. It's a quite large project so I can't just switch to WPF unfortunately. :( @MichaelRandall thanks. I updated the question with a link to microsoft docs *claiming* transparency is possible. https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.form.opacity – CausingUnderflowsEverywhere Oct 13 '20 at 03:38
  • Yeah I was trying to but even setting it to 0 did not make it invisible. The internal "RenderTransparent" property was showing false in the debugger not sure if related. – CausingUnderflowsEverywhere Oct 13 '20 at 03:42
  • Sorry I accidently deleted my comment. Yeah you should be able to get this to work. What version of windows is this ? – TheGeneral Oct 13 '20 at 03:44
  • _The Opacity property enables you to specify a level of transparency __for the form__ and its controls_ - I'm sorry to say that youz are wasting your time. Either give up or switch to WPF.. – TaW Oct 13 '20 at 07:20
  • 1
    Try this: get this Control, [Translucent circular Control with text](https://stackoverflow.com/a/51435842/7444103). To show it transparent on a transparent Form, set the `BackColor` and `TransparencyKey` similar to the Translucent Label's BackColor (the Color in the central section), e.g., in the Form's Constructor, after `InitializeCompoenent()`: `Color c = trasnpasrentLabel.BackColor; this.BackColor = Color.FromArgb(c.R+1, c.G, c.B); this.TransparencyKey = Color.FromArgb(c.R+1, c.G, c.B);`. Remove any form of DoubleBuffering from the Form (it would of course prevent transparency). – Jimi Oct 13 '20 at 11:39
  • @Jimi I ended up just creating a translucent control similar to the one you linked and used it to cover the Control I had, thanks! – CausingUnderflowsEverywhere Oct 13 '20 at 15:53

0 Answers0