Member Avatar for Ajantis

Hello there,

I have some troubles making transparency of my menues in C#. Basically, I can't make them work. :/ I've searched Google, MSDN, codeproject, c-shaprcorner... but I still can't make it work.

I try to set a groupBox BackColor to transparent, and let the groupBox use my own background image (.PNG format).
Can anyone help please?

Here's a bit how I did:

public Form1()
        {
            InitializeComponent();
            this.Closing += new CancelEventHandler(Form1_Closing);
            //I thought this had to be enabled - but didn't work
            //this.SetStyle(ControlStyles.UserPaint, true);
            //ControlStyles.UserPaint = true;
            
            //According to MSDN, this is how it's supposed to be done - but it won't work.
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.BackColor = Color.Transparent;
            this.groupBox1.BackColor = Color.Transparent;

            
        }

Recommended Answers

All 16 Replies

Just select a background color for th GroupBox, then in form properties say that color you selected is Transparent from Form properties
Transparent Key = ?
Example
If you select Red as GroupBox background
Transparent Key = Red

Without writing single line of code!

Member Avatar for Ajantis

Just select a background color for th GroupBox, then in form properties say that color you selected is Transparent from Form properties
Transparent Key = ?
Example
If you select Red as GroupBox background
Transparent Key = Red

Just tried. Didn't work. :(
I tried setting the transparency color to "Maroon", and added that Transparency Key in my Form1.
This was the outcome. I can't see the whole document behind the menu.

I don't know but, did you try to send the menu to back or bring the new document to front?

Member Avatar for Ajantis

I don't know but, did you try to send the menu to back or bring the new document to front?

I don't know what you mean, but - the new document should be placed behind - so that's no problem. But - the maroon color should be transparent in the groupBox, so that the document could show.

Can you send me your code to examine it myself if there's no problem.

Member Avatar for Ajantis

Can you send me your code to examine it myself if there's no problem.

I'm sorry, I can't give out my code. :/ I've been working on it for a very long time. This is all I need to do. Just setting the transparency of the groupBox.

But, does it matter whether the Form is a MDI container, or not?

Why don't you use something like Mygroupbox.BackColor = Color.FromArgb(alpha,Color.Maroon);
alpha being the transparancy : 0 = completly transparant , 255 = completly opaque.
Have not tested it, hope it helps.

Member Avatar for Ajantis

Why don't you use something like Mygroupbox.BackColor = Color.FromArgb(alpha,Color.Maroon);
alpha being the transparancy : 0 = completly transparant , 255 = completly opaque.
Have not tested it, hope it helps.

Just tried it. Won't work. I mean - the code works, but there is no transparency. Only that dull gray "Control Gray" color... which lets nothing through....

It's got the same color as my MDI Container (my form is one). And it just REFUSES to go away in my groupBox.
The effect are the same as in the picture I post earlier, but without the maroon color.

Maybe... I don't know!

Member Avatar for Ajantis

This is a related topic on the code project (in VB!)
http://www.codeproject.com/KB/cpp/UXThemeGroupBox.aspx
Seems to be a difficult problem if you see the remarks.

Yes, it seems to be. :S I also found the original author's code - the guy works for Microsoft. He said it was a difficult problem. Sheesh.
I think I'll drop this for now. :) Until I learn a little more about C#. Nevertheless, it was intressting. Thank you so much people, for your support and help. :) Best wishes!

I found it evenly interesting. Best wishes to you also!:)

Member Avatar for Ajantis

I found it evenly interesting. Best wishes to you also!:)

Thanks friend! :)

Hahaha, i had the same problem last year, welcome to the world of writing your own controls m friend ...

Member Avatar for Ajantis

Hahaha, i had the same problem last year, welcome to the world of writing your own controls m friend ...

Hahahaha :D Thanks mate. Did you solve your problem? :P
Cheers!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.