Click here to Skip to main content
15,902,299 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a listbox in WinForm C#. How do I set the backcolor of this listbox to tranpesent?

I tried
C#
private void Form2_Load(object sender, EventArgs e)
{
    listbox1.BackColor = Color.Transparent;
}


But it doesn't work!
Posted

Transparent doesn't do what you think it does. Try reading the documentation on it.

Transparent tells the control to take on the background properties of the parent container control. It does NOT make the control really transparent. It just gives the illusion by making the control background match the properties of the container background.

Google[^]
 
Share this answer
 
Comments
BillWoodruff 27-Dec-15 0:59am    
In this case, the OP's code sample will throw an error because WinForm Controls do not support transparent background colors. But, the links you refer the OP will show the possible work-arounds (none of which I've ever found useful).
I doubt this is what you want, but if you want to have the ListBox appear as a cut-out in the Form, you can set the TransparencyKey property of the Form to some Color, and set the ListBox BackColor property to the same Color.

Of course, the other ways to do this, as the links that Dave referred you to will show you, involve sub-classing the ListBox.

In my experience with Win Forms, I've never found any satisfactory results with any attempt at using transparency.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900