Click here to Skip to main content
15,880,967 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
I feel silly for asking this, but I'm asking to see what is the preferred solution.

Let's say I have a TabControl with no Tabpages and want the background of the TabControl's body area to be Black instead of White when there are no TabPages. I have also run into the same problem with a 3rd party GridView control.
Posted

Still your question is left without an answer. Here is how you change the background colors.

System.Windows.Forms: see the property BackColor.

WPF: See the property: Background.

Default colors:

System.Windows.Forms: Set color to Control. See also UseVisualStyleBackColor (defaults to true).

WPF: Such properties can be inherited by child controls from parents. Is a property is missing from XAML, it is default. In most case background will be inherited. There are few subtle moments. With WPF you can have different skins with the different style XAMLs, but this is a whole different story.

You did not ask about foreground colors -- so it's you fault if you don't see your black text on your new background. :)

Anyway, when you're comfortable with backgrounds, you will immediately see where to set the foreground colors. :)

Good luck!
 
Share this answer
 
v2
Comments
dan!sh 6-Jan-11 12:47pm    
I thought OP is asking for the preference of background color. :doh: That is why I did not mentioned this. It all depends on the rest of the UI color scheme which color should be used.
wizardzz 6-Jan-11 13:11pm    
I'm sorry SAK, I'm having trouble understanding what you are saying. When you say this:
System.Windows.Forms: see the property BackColor.
and this:
System.Windows.Forms: Set color to Control. See also UseVisualStyleBackColor (defaults to true).
What would the corresponding code look like. Yeah, I know it's bad form to ask for code, but I can't seem to get what you are saying.
fjdiewornncalwe 6-Jan-11 15:02pm    
@d@nish: I still believe that using these properties is the right way to do this. They can be set at runtime based on the current state of the forms they reside on and events taking place. They are the proper way to set them, but the answer should probably be enhanced to mention how to set these values at runtime from event handlers and such.
Sergey Alexandrovich Kryukov 6-Jan-11 23:03pm    
@wizardzz: not very much of the code to understand or not. All the codes are just property assignments. It's the text that important -- what's the purpose of the assigment. OK, some examples:

MyTabControl.UseVisualStyleBackColor = false;
MyTabControl.BackColor = Color.Yellow; //your hard-coded color

as opposed to

MyTabControl.UseVisualStyleBackColor = true;
MyTabControl.BackColor = Color.Control; //default

I did not have too much time for answers. Is somethings is still not clear, let me know -- I'll answer. Better yet, simply try these properties, you will see how they work.
By the way, you don't have to write this code, you can go to Control's Properties page in VS and click here and there -- easy enough.
Sergey Alexandrovich Kryukov 6-Jan-11 23:25pm    
Mark, I did not get it. From what event handlers would it be useful to set color? Only if you're going to modify colors dynamically after the form is shown. (I do not mean event Form.Load. To be frank with you, this is completely stupid event created to please lamers, to created illusion of event-oriented approach and design-mode. This is exactly the same as calling the all the initialization at the end of constructor.)

If the color is supposed to be static, it's enough to set it once from the constructor (as I suggested above) and forget.
I would get rid of the tab control itself if it does not have any tab pages in it.

Edit: Then add the tab control too dynamically.
 
Share this answer
 
v3
Comments
wizardzz 6-Jan-11 11:04am    
The tab control allows users to add / delete tabpages dynamically at runtime. By default, the tabcontrol is empty.
Sergey Alexandrovich Kryukov 6-Jan-11 12:33pm    
The answer makes sense but does not answer the question. Zero number of tabs makes sense, because tabs can be added and removed during run-time -- see almost any modern tab-based text editor. Huh?
wizardzz 6-Jan-11 13:47pm    
Fair enough, I could add/remove the tabcontrol dynamically but it doesn't completely solve the problem. I now have to bug the 3rd party vender of my gridview as to why the backcolor property is not working on their control.
Sergey Alexandrovich Kryukov 6-Jan-11 23:40pm    
@wizardzz: I meant just the opposite: the Answer by d@nish does not provide the answer; instead it provides an excuse for not answering. I explained that this excuse is invalid, because your design does make sense => you still need to change background. This way, I only confirm you may need the answer.
How BackColor property does not work? It basically always works but maybe sometimes effects only a part of background.

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