且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

关于tabcontrol的标题

更新时间:2023-12-06 17:19:28

1。 忘记使用透明度在代码中执行此操作:使用WinForms TabControl,如果不熟悉TabControl的内部结构(它不是.NET!),并且可能使用Win API,则无法执行此操作。请记住,大多数标准的MS ToolBox控件只是.NET包装器,而不是旧的ActiveX / COM控件。



WinForms不是一个很好的技术堆栈,试图使用透明度;尝试WPF,如果你想要真实,并且想要透明度。



2.你可以模拟这个图形外观在WinForms中执行以下操作:



a。将Panel,'Panel1'拖放到Form上:将'BackColor'设置为'Navy,或者其他。



b。将Panel,'Panel2'拖放到'Panel1:将其'BackColor'设置为'GhostWhite,或者其他什么。尺寸它所以它覆盖了所有'Panel1,除了最顶部的水平条除外。



c。将TabControl拖放到'Panel1:将其定位,使其Tabs-bar的非客户区域是'Panel1的颜色显示的区域。将TabControl的TabPages设置为你想要的'BackGroundColor。



d。你必须确保将TabControl放入'Panel1,而不是'Panel2!



这是使用Panels和TabControl的结果的屏幕截图: [ ^ ]。



我认为这种解决方案是一种UI黑客,还有一些需要避免的事情:如果主机表单调整大小,你还没有使用Anchor或Dock做正确的事情设置,你可能有错误的对齐。



如果我真的需要这个外观,我只需要在一个面板中使用TabControl进行UserControl。


  protected  覆盖  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 。宽度, .Height - .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);
}


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?

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.


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);
}