我正在開發一個ERP項目。它是treeView框上的一個按鈕,當它在treeView中點擊一個按鈕時,它必須創建一個帶有內容的Tab(之前定義的內容)。使用其內容添加製表符到製表符
我可以programically添加一個標籤,但我如何設計其內容?
我正在開發一個ERP項目。它是treeView框上的一個按鈕,當它在treeView中點擊一個按鈕時,它必須創建一個帶有內容的Tab(之前定義的內容)。使用其內容添加製表符到製表符
我可以programically添加一個標籤,但我如何設計其內容?
添加一個新的用戶控件的項目,然後使用設計做控制/佈局,然後當你點擊你要做的就是添加用戶控件到標籤的新實例 - 可能停靠除非填寫標籤頁中的表格的大小是固定的。
請給我一些更詳細的信息 –
看看@pondidum做了什麼(+1) –
添加以下內容到樹視圖中點擊事件應該做你所追求的:
var contentControl = new ContentControl(); //This is what we will put all your content in
contentControl.Dock = DockStyle.Fill;
var page = new TabPage("Tab Text"); //the title of your new tab
page.Controls.Add(contentControl); //add the content to the tab
TabControl1.TabPages.Add(page); //add the tab to the tabControl
到項目中,添加一個新的UserControl
稱爲ContentControl中(或任何你需要的,只是在我的例子中使用這個) ,並填寫您希望顯示在標籤中的所有內容。
你有幾個解決方案,最簡單的就是創建TabPage
,創建期望的控制,設置其屬性(即大小,位置,文本等),將它們添加到TabPage
,然後添加TabPage
到TabControl
。
TabPage tp = new TabPage();
//create controls and set their properties
Button btn1 = new Button();
btn1.Location = new Point(10,10);
btn1.Size = new System.Drawing.Size(30,15);
//add control to the TabPage
tp.Controls.Add(btn1);
//add TabPage to the TabControl
tabControl1.TabPages.Add(tp);
第二個解決方案是重寫TabPage
在你的類,例如CustomTabPage
在這裏設置了控制在類的構造函數。然後,當您要添加新的TabPage
時,請創建您的CustomTabPage
實例並將其添加到TabControl
。
public class CustomTabPage : TabPage
{
public CustomTabPage()
{
//create your Controls and setup their properties
Button btn1 = new Button();
btn1.Location = new Point(20, 20);
btn1.Size = new System.Drawing.Size(40, 20);
//add controls to the CustomTabPage
this.Controls.Add(btn1);
}
}
//Create CustomTabPage
CustomTabPage ctp = new CustomTabPage();
tabControl1.TabPages.Add(ctp);
第三溶液(最好的,但最複雜的)是創建所需UserControl
你想要它(您可以使用Designer幫助),然後創建您的UserControl
的實例,創建一個TabPage
一切,在TabPage
上添加UserControl
。然後將TabPage
添加到TabControl
。
public partial class CustomControlForTabPage : UserControl
{
public CustomControlForTabPage()
{
InitializeComponent();
}
}
//Create CustomControl
TabPage tp = new TabPage();
CustomControlForTabPage ccftp = new CustomControlForTabPage();
//set properties you like for your custom control
tp.Controls.Add(ccftp);
tabControl1.TabPages.Add(ctp);
贏?網? WPF? –
windows桌面應用程序 –
您面臨的問題是什麼? –