Reputation: 180798
I have a TabControl
, to which I am programmatically adding a Form
with a GridView
control on it to the Tab Controls Controls
collection. The result looks like this:
The GridView in the illustration actually has about 150 columns... When I use the horizontal scroll bar to scroll to the right, I get this:
Notice that the scroll-bar is not staying in the visible client area of the tab. Instead, the scroll bar is assuming the width of the embedded form.
How do I get the scroll bar to assume the width of the visible client area in the tab?
Here is my code. PcmEditorForm
is just a blank form, with FormBorderStyle
set to none, and there is some code that sets the number of rows and columns in the grid that's not shown here:
private void LoadEditorTab()
{
var editor = new PcmEditorForm();
var grid = new GridView();
editor.Width = grid.Width;
editor.Height = grid.Height;
editor.Controls.Add(grid);
editor.AutoScroll = true;
editor.Anchor = AnchorStyles.Left | AnchorStyles.Top;
tabEdit.Controls.Clear();
editor.TopLevel = false;
editor.Visible = true;
tabEdit.Controls.Add(editor);
}
Upvotes: 0
Views: 1016
Reputation: 4354
Why don't you just dock the editor in the tabEdit.
private void LoadEditorTab()
{
var editor = new PcmEditorForm();
var grid = new GridView();
grid.width=editor.width
grid.Anchor= AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
editor.Controls.Add(grid);
tabEdit.Controls.Clear();
editor.TopLevel = false;
editor.Visible = true;
editor.dock=DockStyle.Fill; // Dock the editor
tabEdit.Controls.Add(editor);
}
Upvotes: 1