xpda
xpda

Reputation: 15813

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 to do with the tabcontrol? Or am I better off using a panel control when only one file (tab) is open?

Upvotes: 2

Views: 3473

Answers (3)

Amitd
Amitd

Reputation: 4859

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

Building C# .NET windows application with multiple views

Upvotes: 1

Hans Passant
Hans Passant

Reputation: 942109

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

Upvotes: 6

o.k.w
o.k.w

Reputation: 25820

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.

Upvotes: 0

Related Questions