【发布时间】:2018-12-13 09:31:22
【问题描述】:
我有一个面板,它有多个动态添加的用户控件(都一样),我需要查看是否选中了一个复选框以及每个控件中的 label.text 是什么。不确定如何获得这些值?
这是将用户控件添加到面板的位置
private void Employee_Add_Load(object sender, EventArgs e)
{
List<string> VehicleTypes = DAL.LicenseDAL.GetAllVehicleTypes();
foreach (string Vehicle in VehicleTypes)
{
User_Controls.Vehicle_Bar VTB = new Vehicle_Bar(Vehicle);
pnlVehicleChecks.Controls.Add(VTB);
}
}
这是用户控件(实际上只是一个标签和复选框)
public partial class Vehicle_Bar : UserControl
{
public string Vehicle = "";
public Vehicle_Bar(string vehicle)
{
Vehicle = vehicle;
InitializeComponent();
}
private void Vehicle_Bar_Load(object sender, EventArgs e)
{
lblType.Text = Vehicle;
}
}
所有这些复选框都适用于员工的车辆执照,具体取决于选中的复选框取决于允许他们驾驶的车辆
【问题讨论】:
-
您可以在表单中为您的
usercontrol提供onclick事件。在form中的foreach循环中为usercontrol声明onclick事件