views:

1986

answers:

4

The standard System.Windows.Forms.TabControl component draws a border around the TabPages it contains. If you set its Dock to Fill, these borders run up to the edge of the parent control, but they're still there, taking up screen space.

In Visual Studio, if you dock two windows in the same place, you get a TabControl-like set of tabs along the bottom, but no borders along the sides.

Is it possible to get a TabControl to display its TabPages in this manner, with no wasted screen space at the sides? If possible, I'd like to avoid solutions that involve painting the control myself.

+1  A: 

Instead of using the Dock property you should try using the Anchor to anchor each of the four sides. Then you need to position the TabControl so it is positioned a couple of pixels bigger on all sides that the parent. That way the borders are hidden because they cannot be drawn when behind the parent control.

Phil Wright
Will that work identically irrespective of the user's theme and accessibility settings?
Simon
A: 

Anchor the left and right sides of the control with the width set to the width of the parent control.

childControl.Anchor = Anchor.Left|Anchor.Right; childControl.Width = parentControl.Width;

Pat
A: 

Do not Dock the TabControl. Stretch it out on the designer so its left and right edges extend beyond the window.

Will that work identically irrespective of the user's theme and accessibility settings? It seems to me that if their theme is different, the distance beyond the edges might need to be different.
Simon
A: 

Using the standard .NET tab control, this isn't directly possible. What is the ultimate goal for this? Are you trying to simulate the same type of tabbed-MDI style display as Visual Studio? If that's the case, there are several third-party solutions available - some open source and some commercial.

The other responses about using the Anchor property in combination with setting the size so it is just a bit larger than the actual window might work, but I think it might look a bit odd visually. It should work regardless of the theme and accessibility settings, but you may end up having to programmatically set the size to be a few pixels larger than the parent.

Scott Dorman