开发者

Tabcontrol: How can you remove the tabpage title?

I have a tabcontrol used to display multiple image files in an application. I would like to remove the tabpage title when there is only one tabpage displayed, so I can use that screen space for the image. (This is similar to deselecting "Always show the tab bar" in Firefox.)

Is this possible t开发者_如何学JAVAo do with the tabcontrol? Or am I better off using a panel control when only one file (tab) is open?


Yes, this is possible. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form.

using System;
using System.Windows.Forms;

public class MyTabControl : TabControl {
  private int mPages = 0;
  private void checkOnePage() {
    if (IsHandleCreated) {
      int pages = mPages;
      mPages = this.TabCount;
      if ((pages == 1 && mPages > 1) || (pages > 1 && mPages == 1))
        this.RecreateHandle();
    }
  }
  protected override void OnControlAdded(ControlEventArgs e) {
    base.OnControlAdded(e);
    checkOnePage();
  }
  protected override void OnControlRemoved(ControlEventArgs e) {
    base.OnControlRemoved(e);
    checkOnePage();
  }
  protected override void WndProc(ref Message m) {
    // Hide tabs by trapping the TCM_ADJUSTRECT message
    if (m.Msg == 0x1328 && !DesignMode && this.TabCount == 1) m.Result = (IntPtr)1;
    else base.WndProc(ref m);
  }
}


try using the answer given here :) .. setting the region of the tab

Building C# .NET windows application with multiple views


I do not recall any means to hide the tab label. My recommendation:

Have your tab contents in panels. When only one tab, move the panel put to replace the tabcontrol or something of that nature.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜