954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Setting transparency color in a groupBox

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;

            
        }
Ajantis
Junior Poster in Training
58 posts since Aug 2008
Reputation Points: 13
Solved Threads: 0
 

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

Attachments Transparncy.jpg 23.48KB
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

Without writing single line of code!

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 
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.

Attachments Namnlös.jpg 13.59KB
Ajantis
Junior Poster in Training
58 posts since Aug 2008
Reputation Points: 13
Solved Threads: 0
 

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

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 
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.

Ajantis
Junior Poster in Training
58 posts since Aug 2008
Reputation Points: 13
Solved Threads: 0
 

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

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 
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?

Ajantis
Junior Poster in Training
58 posts since Aug 2008
Reputation Points: 13
Solved Threads: 0
 

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.

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 
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.

Ajantis
Junior Poster in Training
58 posts since Aug 2008
Reputation Points: 13
Solved Threads: 0
 

Maybe... I don't know!

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

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.

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 
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!

Ajantis
Junior Poster in Training
58 posts since Aug 2008
Reputation Points: 13
Solved Threads: 0
 

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

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 
I found it evenly interesting. Best wishes to you also!:)

Thanks friend! :)

Ajantis
Junior Poster in Training
58 posts since Aug 2008
Reputation Points: 13
Solved Threads: 0
 

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

cVz
Junior Poster
140 posts since Mar 2008
Reputation Points: 29
Solved Threads: 7
 
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!

Ajantis
Junior Poster in Training
58 posts since Aug 2008
Reputation Points: 13
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You