Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
the picture as below:
http://img.bbs.csdn.net/upload/201412/18/1418888196_802878.jpg

the tabcontrol do not have the backcolor property。
how can i set the header's backcolor to tansparent.
can let the 1 index's backcolor as same as 2 index's backcolor.

can i program tabcontrol component,
not through other way?
Posted
Updated 19-Dec-14 19:33pm
v2

1. Forget about doing this in code using transparency: with the WinForms TabControl, you cannot do this without being intimately familiar with the TabControl's internal structure (it's not .NET !) and, possibly using Win API's. Remember that most of the standard MS ToolBox Controls are just .NET wrappers around rather old ActiveX/COM Controls.

WinForms is not a good technology stack for trying to use transparency; try WPF if you want real, and fancy, transparency.

2. You can simulate this graphic appearance in WinForms by doing the following:

a. drag-drop a Panel, 'Panel1, onto a Form: set its 'BackColor to 'Navy, or whatever.

b. drag-drop a Panel, 'Panel2, into 'Panel1: set its 'BackColor to 'GhostWhite, or whatever. size it so it covers all of 'Panel1 except except a topmost horizontal strip.

c. drag-drop a TabControl into 'Panel1: position it so the non-client area of its Tabs-bar is the area where 'Panel1's color is showing through. set the TabPages of the TabControl to the 'BackGroundColor you want.

d. you'll have to make sure you put the TabControl into 'Panel1, not 'Panel2 !

Here's a screen capture of the result of using the Panels and a TabControl: [^].

I regard this kind of solution as kind of a "UI hack," and something to be avoided: if the host Form is resized, and you haven't done the right thing with Anchor or Dock settings, you could have mis-alignment.

If I really had to have this "look," I'd make a UserControl with just the TabControl in one Panel.
 
Share this answer
 
v2
C#
protected override void OnPaintBackground(PaintEventArgs pevent)
{
    Graphics g = pevent.Graphics;

    Rectangle recHeader = new Rectangle(this.ClientRectangle.X, this.ClientRectangle.Y, this.ClientRectangle.Width, this.ItemSize.Height+2);
    Rectangle recPage = new Rectangle(this.ClientRectangle.X, this.ClientRectangle.Y + this.ItemSize.Height, this.Width, this.Height - this.ItemSize.Height);


    if (this.TabCount > 0)
    {
        SolidBrush pageBrush = new SolidBrush(SystemColors.Control);
        g.FillRectangle(pageBrush, recPage);
    }

    SolidBrush headerBrush = new SolidBrush(SystemColors.ActiveCaption);
    g.FillRectangle(headerBrush, recHeader);
}
 
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