I have a user control which has text boxes and date picker.
(我有一个带有文本框和日期选择器的用户控件。)
When the form load, Dynamically generate the user control and display in the form. (加载表单后,动态生成用户控件并在表单中显示。)
(EventComponent (user control) image ). ((EventComponent(用户控件) 图片 )。)
I want to get each of these user control values when the user clicks the save button.
(当用户单击“保存”按钮时,我想获取每个这些用户控件值。)
namespace WeekNote.Forms
{
public partial class InsertEventForm : Form
{
private int numberOfEvent;
public InsertEventForm(int numberOfEvent)
{
InitializeComponent();
this.numberOfEvent = numberOfEvent;
}
private void InsertEventForm_Load(object sender, EventArgs e)
{
EventComponent[] eventComponents = new EventComponent[(int)this.numberOfEvent];
int i = 0;
Button backBTN = new Button();
backBTN.Text = "Back";
backBTN.Location = new Point(0, 10);
backBTN.Size = new Size(50, 30);
this.Controls.Add(backBTN);
// generate user control dynamically here
for ( i = 0; i < eventComponents.Length; i++)
{
eventComponents[i] = new EventComponent();
System.Drawing.Point pLabel = new System.Drawing.Point(36, 50 + i * 280);
eventComponents[i].Location = pLabel;
eventComponents[i].Size = new System.Drawing.Size(358, 259);
this.Controls.Add(eventComponents[i]);
}
Button saveBTN = new Button();
saveBTN.Text = "Save";
saveBTN.Location = new Point(200, 50 + i * 280);
saveBTN.Size = new Size(100, 50);
this.Controls.Add(saveBTN);
saveBTN.MouseEnter += new System.EventHandler(this.SaveBTN_click);
}
private void SaveBTN_click(object sender, EventArgs e)
{
// need to retieve value from user control
}
}
}
ask by Gayathra Madubashana translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…