我在面板中動態添加了複選框,並且在執行後,如何獲得單擊按鈕時選中哪個複選框。獲取動態添加的複選框的檢查狀態
public int x=550 ,y=10;
private void Form1_Load(object sender, EventArgs e)
{
var panel1 = new Panel()
{
Size = new Size(600, 70),
Location = new Point(20, 130),
BorderStyle = BorderStyle.FixedSingle
};
for (int i = 0; i < 20; i++)
{
CheckBox chkpremiumtickets = new CheckBox();
chkpremiumtickets.Text = " ";
chkpremiumtickets.Name = "chkboxpremiumtickets";
chkpremiumtickets.Location = new Point(x,y);
panel1.Controls.Add(chkpremiumtickets);
x = x - 55;
if (x < 55)
{
y = y+20;
x = 550;
}
}
x = 550; y = 10;
Controls.Add(panel1);
他的控件是動態的,所以不會幫助! –