As far as I can see TabControl object has no properties of either Back or ForeColor. Is it possible to assign these properties to this object
Another question:
TabPage object does have both properties but when you assign a color to it it does not cover the whole TabPage: the tab itself remains gray. Is it possible to give it colors
Many thanks.

Coloring TabControl.
aschaeffer
TabControl inherits from Control so the properties BackColor and ForeColor *are* present. They have just been hidden from the VS designer. If you manually assign them (don't believe what intellisense tells you! :) ) It will compile.
Unfortunately, modifying them seems to have no effect on the painting of the control. I'm not sure how you can overcome this problem directly.
I would design my own UserControl to mimic the TabControl that you *can* choose the colours for.
bpeikes
Trying to find a straw to catch up and hang on:
MSDN says that Control Class does not have BackColor property. It is not mentioned at all, however the TabControl Class does, it is overridden, but it "has no meaning" in TabControl. Sounds funny. Why did they even menton it at all.
Building a CustomUserControl might be a tall order for me since I've never done it before. I looked at the class description. They give a simplistic example of putting together a few texboxes and labels. I do not know how I can take it from there.
Thanks.
Desprate Me
With a fair amount of effort it is possible to get the TabControl to do exactly what you want.
You will find some basic tips on my TabControl Tips page:
http://www.dotnetrix.co.uk/tabcontrols.html
You will also find TabControlEx (an extended TabControl) in my Controls section which will allow you to change the colors via a simple property change:
http://www.dotnetrix.co.uk/controls.html
edit: Fixed the first link.
Eric White King
The TabControls DisplayRectangle is the Area in which the TabPage is Docked, so it changes as Rows are added/removed.
Presumably you have access to the method which Adds/Removes the Tabpages. In this method you could simply check the height of the TabControls DisplayRectangle and if it does not equal the Desired TabPage Height then adjust Form/TabControl height to compensate.
jim rozak
I just created a small Test App to recreate your scenario and didn't see any problems.
I defined a variable to store the desired TabPage Height and set it in the Constructor after InitializeComponent().
I added a tabPage_SizeChanged eventhandler to all tabpages (if tabPage1 is not selected it will not fire the SizeChanged event until it is).
I checked and modified the height of the Form and TabControl when the tabPage_SizeChanged() event occurred.
Here's the C# code I used in the SizeChanged method:
private void tabPage_SizeChanged(object sender, EventArgs e) { TabPage tabPage = (TabPage)sender; if (tabPage.Height != this.desiredTabPageHeight) { this.Height += (this.desiredTabPageHeight - tabPage.Height); this.tabControl1.Height += (this.desiredTabPageHeight - tabPage.Height); } }... of course, it is possible to have no tabpage selected (SelectedIndex = -1) and then this method would fail as the tabPage_SizeChanged event would never occur, but that is only likely to happen if you code it to do so.
Bruno177
http://msdn2.microsoft.com/en-us/library/system.windows.forms.control_members.aspx
TabControl technically does but it's description is "Overridden. This member is not meaningful for this control." So they've hidden it from the VS designer, since you can't completely remove an inherited property:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.tabcontrol_members.aspx
Designing your own UserControl can be quite daunting if you've not done it before. I would structure it like the TabControl. I would create the main MyTabControl and create a MyTabPageControl. Using Generics you could add this to the MyTabControl class and reveal it as a property. Then you could work with it in exactly the same way you work with TabPages:
using System.Windows.Forms;
using System.Collections.Generic;
public class MyTabControl : UserControl
{
private List<MyTabPageControl> myTabPages;
public List<MyTabPageControl> MyTabPages
{
get { return myTabPages; }
set { myTabPages = value; }
}
}
The hard part would be positioning the tabs. Having said all that I don't think the benefit of being able to change the tab color outweighs the work involved...
Torpedo
madhura_b
Compiling should not actually modify anything you've written. It may throw a wobbly but not modify.
Drore
That's what I am too afraid is the case as well.
I greatly appreciate your comments. I will look into the details tomorrow and make a decision if it is worth the labor.
Thanks.
DPotages
Thank you Mick. The first link is unreachable for me (error 404). I will take a look at the second link tomorrow.
Hassan Ayoub
Thank you very much. I am wondering if you've done it yourselves, though, I just did after I read your post and this is what happened: it did compile all right but when I looked back at the code in the constructor the statement tabControl1.BackColor = was gone. Alas.
A catch22.
Beetle54
I do not use DisplayRectangle. I use the .Size objects instead. I will think of it. Perhaps it will offer an advantage. The method that adds and removes pages helps little with it. I rely on the .SizeChanged (for the first page only since the first 5 pages are permament and cannot be destroyed--I designed them this way). On the way forward when the pages are added and when threashold is reached (12 pages in my case) this event fires. To adjust the size of (1) the form and (2) TabControl I have resorted to creating an object that keeps sizes of both at loading time. This object is static and therefore accessible to the Click event for the button that destroys the TabPage (a button per each TabPage). Then I have to keep statically the number of pages when the rows were doubled (12 in my case) and perhaps trippled (in the future). I have to set the SizeChanged event to null temporarily when I resize the form and TabControl down and the whole thing is clumsy and messy. As I said everything works with the exception of leaving me with a larger form height after the reduction. If I add another page just after I reduced the number of pages from 13 to 12 making the number 13 again my form will keep getting taller. I thought you may see a more elegant solution. I will look into DisplayRectangle object though.
Thanks.
Chiro
Mick, thank you very much. It is GREAT! Just a very useful set of controls. Absolutely fantastic!
When I posted the question a few days ago about the coloring I thought to myself: it is a long shot but parhaps You never know.
Steve Kibble
Mick, thank you again. I want to add one more challenge for you. This is the problem I've encountered and haven't been able to solve so far cleanly. It works only partially for me, although I haven't given it a lot of attention yet.
I generate TabPages at runtime and frequently have to reduce their number. I want to completely destroy the object, not to hide it. It works. This is not a problem, however:
When the first row of tabs is filled, the app begins to fill the second row. By doing so it has to decrement the height of the existing pages in order to fit them in TabControl and the form itself. It screws my graphics positioned on the additional pages I've created. I neatly soved the problem by using sizeChanged event for TabPage but so far it worked only in one direction when the number of pages gets large enough for the app to form two rows. When I decrease the number to drop from two to one row I end up with form and TabControl retaining the enlarged heights.
So, if this is an interesting problem for you, would you give it a thought