簡體   English   中英

在C#中將組件附加到GroupBox

[英]Attach components to GroupBox in C#

我想在表單中插入一個組框,並在其中放入3個單選按鈕。

將3個單選按鈕連接到組合框是否有任何優勢。 駕駛室,我們甚至這樣做?

如果我必須這樣做,我如何將3個單選按鈕附加到組框,以便它們成為組框的一部分而不是表單上的單獨組件?

如果你正在談論winforms; 只需將單選按鈕控件拖到窗體設計器中的GroupBox 如果你想以編程方式添加它們,這樣的東西應該工作:

RadioButton rb = new RadioButton();
rb.Text = "Some text";
myGroupBox.Controls.Add(rb);
rb.Location = new Point(someX, someY);

// repeat as necessary

在代碼中,假設您有一個groupbox變量名groupBox1:

groupBox1.Controls.Add(radioButton1);
groupBox1.Controls.Add(radioButton2);
groupBox1.Controls.Add(radioButton3);

如果你的意思是設計師,只需將radiobuttons拖到組框而不是表格上。

你也可以在一行上做到:

groupBox1.Controls.AddRange(new Control[] { radioButton1, radioButton2, radioButton3 });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM