views:

1152

answers:

1

I have a TabControl consisting of several TabPages. One of these TabPages contains a TreeView and another contains a DataGridView. I would like these controls (and tabpages) to AutoSize to the maximum size allowed in the TabControl without scrolling.

The DataGridView contains an AutoSize property inherited from Control which garbles the control if enabled. The TreeView does not have this property. I have tried setting the Size equal to TabControl.Size but that does not account for bordersize and the Tabbar height.

treeView.Size = new Size(tabControl.Size.Width - SystemInformation.Border3DSize.Width * 2, tabControl.Size.Height - SystemInformation.Border3DSize.Height * 2);

My question is: how can I determine the height of the Tab buttons or how can I automatically fill TabPages to their maximum size with a single control?

+4  A: 

The Property you search is called Dock.

You probably want to set it to DockStyle.Fill on your TreeView and DataGridView.

An alternative would be to set the Anchor Property to AnchorStyle.Top, AnchorStyle.Left, AnchorStyle.Right and AnchorStyle.Bottom (concatenate with binary OR the pipe sign '|'). For that you would need to set the size of the Children to ClientSize

Sven Hecht
This does not work unfortunately. It docks the controls to the TabPages which do not dock to the TabControl. TabPages also do not contain a Dock or Anchor property.
Wouter
as far as i know tabpages do use the complete clientsize of the tabcontrol or how do you use them?
Sven Hecht
I use it in the normal way: `TabControl t = new TabControl(); TabPage tp = new TabPage(); t.TabPages.Add(tp);` I then continue to set the size and location of the tabcontrol. Any suggestions of how to scale the TabPage to fill the TabControl?
Wouter
i can't image how a tabpage cannot fill the tabcontrol. I think I don't understand what your problem is...a screenshot?
Sven Hecht