我製作了一個代碼,旨在製作帶有關聯標籤的組合框。我怎樣才能讓標籤顯示在組合框中找到的值。C# - 動態控件(組合框+標籤)
每次按下按鈕時都會提供一個組合框和一個標籤,所以會有x個組合框和標籤。
ArrayList cboRunList = new ArrayList();
ArrayList labRunList = new ArrayList();
private void button1_Click(object sender, EventArgs e)
{
// Tilføjer ComboBoxe
ComboBox cboRun = new ComboBox();
string[] s = { "", "a", "b", "c", "d", "1", "2", "3", "4" };
cboRun.DataSource = s;
cboRun.Location = new System.Drawing.Point(10, 10 + (20 * c));
cboRun.Size = new System.Drawing.Size(200, 25);
cboRunList.Add(cboRun);
cboRun.Click += new EventHandler(cboRun_Click);
Controls.Add(cboRun);
// Tilføjer label
Label labRun = new Label();
labRun.Name = "LabDyn" + c;
labRun.Location = new System.Drawing.Point(270, 10 + (20 * c));
labRun.Size = new System.Drawing.Size(1000, 20);
labRunList.Add(labRun);
labRun.Text = "LabDyn" + c;
Controls.Add(labRun);
c = c + 1;
我們不知道如何在不看到原始代碼的情況下對現有代碼庫進行更改。請發表[需要更改的最簡單示例](http://stackoverflow.com/help/mcve),並完整說明需要修改的內容。 – gunr2171 2014-10-01 14:44:37
您需要創建一個'UserControl'。 – 2014-10-01 14:44:39
爲了獲得代碼,必須先給代碼。 – DidIReallyWriteThat 2014-10-01 14:44:53