0
我有三層體系結構。頂層是我的GUI,第二層是我的商務類。在GUI上有很多複選框(+20項)和一個「開始」按鈕可用。如果用戶點擊按鈕,我想通過構造函數將複選框的狀態移交給業務對象。將多個複選框的狀態切換到業務層的常用方法
要通過List<Checkbox>
不是一種合適的方式,解決方案應該靈活適應變化。此外,我需要在業務層上標識複選框狀態的可能性。是否有共同的可能性來解決這個問題?
這裏一個例子,我的問題:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
for (int i = 0; i < 20; i++)
{
flowLayoutPanel1.Controls.Add(CreateCheckbox(i));
}
var button = new Button();
button.Name = "StartButton";
button.Text = "Start";
button.Click += new EventHandler(button_Click);
flowLayoutPanel1.Controls.Add(button);
}
private void button_Click(object sender, EventArgs e)
{
var businessObject
= new BusinessClass(/*How to handover the checkbox status*/);
}
private CheckBox CreateCheckbox(int index)
{
var checkBox = new CheckBox();
checkBox.Name = "checkBox" + index;
checkBox.Text = "checkBox" + index;
return checkBox;
}
}