2

I have a custom graphing usercontrol which has support for transparent backcolor. During design, the usercontrol shows properly. However, on runtime, the backcolor turns black.

Chart on Runtime

I have searched stackoverflow for a solution, but most of the articles refer to WPF or controllers. :(

Things I have tried:

I have tried using a transparentpanel usercontrol to house the graphing usercontrol. This changed nothing. I set the graphing usercontrol to use the transparentpanel as the parent, nothing.

Does anybody have any input on how to prevent this from happening? Thank you.

Update 1: If I just add the graphing usercontrol to the form and run the app, the transparency still works. It seems to be an issue when it starts graphing. I have tried the following solutions.

    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams parameters = base.CreateParams;
            parameters.ExStyle |= WS_EX_TRANSPARENT;
            return parameters;
        }
    }

    internal const int WS_EX_TRANSPARENT = 0x00000020;

I also tried adding:

        this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        this.SetStyle(ControlStyles.OptimizedDoubleBuffer, false);
frostbyte
  • 430
  • 5
  • 13
  • Isn't this the same issue as [Transparent Overlapping Circular Progress Bars (Custom Control)](https://stackoverflow.com/q/53365918/719186) – LarsTech Nov 20 '18 at 17:06
  • I never had a problem with the transparency of the circularprogressbars to form. Just when they overlapped. This is straight up on the form. – frostbyte Nov 20 '18 at 17:07
  • Well, what's different? – LarsTech Nov 20 '18 at 17:08
  • Is this related to your [previous question](https://stackoverflow.com/questions/53365918/transparent-overlapping-circular-progress-bars-custom-control/53379442#53379442)? *transparentpanel usercontrol* what does it mean? Is this a `CustomControl` or a `UserControl` (different stuff)? Are you setting the `BackColor` to `Color.Transparent` at some point? Post the code related to the drawing. – Jimi Nov 20 '18 at 17:08
  • `I set the graphing usercontrol to use the transparentpanel as the parent` I'm guessing this is your issue. WinForms never has true transparency, just copying the background of the parent container. – LarsTech Nov 20 '18 at 17:11
  • Thanks for your help LarsTech and Jimi. Turned out to be something stupid. :) – frostbyte Nov 20 '18 at 19:27

1 Answers1

1

I had a similar problem to this. I searched Google and found my answer. I don't know your code for your custom control, but take a look for a line like this in your OnPaint:

e.Graphics.Clear(Color.Transparent);

The function "Clear" used with the "Transparent" color is not going to make your custom control transparent. It essentially paints the color transparent over your entire control. This can lead to some pretty funky results.

Alexandra
  • 28
  • 5