2012-07-03 39 views
0

我有一個TabControl,我正在編程上在它上面添加一個Form,其上的GridView控件添加到Tab控件Controls集合中。結果是這樣的:滾動條不留在Winforms選項卡控件中的客戶區域內

enter image description here

GridView控件圖中居然有大約150列...當我使用水平滾動條滾動的權利,我得到這個:

enter image description here

請注意,滾動條不在選項卡的可見客戶端區域中。相反,滾動條呈現嵌入表單的寬度。

如何讓滾動條呈現標籤中可見客戶區的寬度?

這是我的代碼。 PcmEditorForm只是一個空白表格,與FormBorderStyle設置爲無,並有一些代碼,將我們在這裏不會顯示網格中的行和列數:

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

回答

1

你爲什麼不只是停靠編輯器在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); 
    } 
+0

'Dockstyle.Fill'沒有辦法。錨樣式似乎並不重要。 –

相關問題