BradR

I'm trying to implement something similar to the Java Card layout - a tab control where the tabs are not visible. I found a useful link that shows how to prevent the actual tabs from being displayed. It works great, however, there is a 3px margin/padding that I can't seem to get rid of. Wondering if someone can point me in the right direction. here is the code i'm using

Code Snippet

this.tabControl1.Appearance = TabAppearance.Buttons;

this.tabControl1.SizeMode = TabSizeMode.Fixed;

this.tabControl1.ItemSize = new Size(0, 1);

this.tabControl1.Alignment = TabAlignment.Top;

this.tabControl1.Padding = new Point(0, 0);

this.tabControl1.Margin = new System.Windows.Forms.Padding(0);

foreach (TabPage t in this.tabControl1.TabPages)

{

t.Padding = new System.Windows.Forms.Padding(0);

t.Margin = new System.Windows.Forms.Padding(0);

}



Re: Windows Forms General HowTo Remove TabControl Margin

nobugz

I think you'll have little hope of getting rid of this, there appears to be a hard-coded margin between the TabControl border and its pages. Look like about 3 pixels to me. How about a UserControl with a bunch of panels Or a panel with a bunch of UserControls As far as the design-time experience, this current thread is relevant...





Re: Windows Forms General HowTo Remove TabControl Margin

BradR

That is what i was afraid of

I have used a custom control in the past to accomplish the card layout. However, I was hoping I could get back to using more of the standard visual studio components. Less code for me to maintain...

Thanks for the response





Re: Windows Forms General HowTo Remove TabControl Margin

BradR

is it possible there is a message i can trap by overriding the WndProc method to prevent the control from setting this 3px padding



Re: Windows Forms General HowTo Remove TabControl Margin

nobugz

TCM_ADJUSTRECT (0x1328) looks promising...





Re: Windows Forms General HowTo Remove TabControl Margin

Mick Doherty

1. You can modify the standard TabControl by changing it's displayrectangle. You'll see this in the Add a HideTabs property to turn on/off the Tabs example at:

http://www.dotnetrix.co.uk/tabcontrols.html

This solution would have the same effect as the one Hans suggested (TCM_ADJUSTRECT).

2. You can create a custom control to do the same job as in the Create a PanelManager example at:

http://www.dotnetrix.co.uk/custom.html

Due to a bug in the VS2005 designtime environment, you must create a dll for the PanelManager class and reference that from your solution. If you simply add the class to your solution you will find that it works fine until a rebuild, where it will lose reference to the ManagedPanels collection. In VS2003 you can simply add the class to your project and it will work without error.





Re: Windows Forms General HowTo Remove TabControl Margin

BradR

TCM_ADJUSTRECT worked even better than I thought. In order to create the card layout, i simply wrote the following control. In design time it shows the tabs, and in run time is hides them.

Code Snippet

using System;
using System.Collections.Generic;
using System.Text;

namespace WindowsApplication1
{
public class CardLayoutControl : System.Windows.Forms.TabControl
{
private const int TCM_ADJUSTRECT = 0x1328;
protected override void WndProc(ref System.Windows.Forms.Message m)
{

if (m.Msg == TCM_ADJUSTRECT && !DesignMode)
{ }
else
{
base.WndProc(ref m);
}
}
}
}





Re: Windows Forms General HowTo Remove TabControl Margin

nobugz

Sweet! TabControl is rarely that accommodating...





Re: Windows Forms General HowTo Remove TabControl Margin

Mick Doherty

Very nice. Much cleaner than either of my suggestions.

I would also make sure that Multiline is set to true at runtime so that the UpDown control (which doesn't work using this method) does not show.