I have a Form1
with a align_Click
button on it. align_Click
button creates a Form2
with a 3 Buttons
and 3 TextBoxes
. Each of these Button
s creates another Form3
with a ComboBox
and a 'Button'. All controls listed above are created dynamically,not in the Design-Mode. How can I pass the value of Combobox
from Form3
to Textbox
in Form2
? I have difficulties in writing an EventHandler for the Button
in Form3
, aka aOK_Click
Here is code snippet :
public void align_Click(object sender, EventArgs e)
{
Button alignContentBtn = new Button();
alignContentBtn.Location = new System.Drawing.Point(86, 8);
alignContentBtn.Size = new System.Drawing.Size(47, 23);
alignContentBtn.Text = "Seç";
alignContentBtn.Click += new EventHandler(this.alignContentBtn_Click);
alignForm.Controls.Add(alignContentBtn);
Button alignItemsBtn = new Button();
alignItemsBtn.Location = new System.Drawing.Point(86, 43);
alignItemsBtn.Size = new System.Drawing.Size(47, 23);
alignItemsBtn.Text = "Seç";
// alignItemsBtn.Click += new EventHandler(this.alignItemsBtn_Click);
alignForm.Controls.Add(alignItemsBtn);
Button alignSelfBtn = new Button();
alignSelfBtn.Location = new System.Drawing.Point(86, 77);
alignSelfBtn.Size = new System.Drawing.Size(47, 23);
alignSelfBtn.Text = "Seç";
// alignSelfBtn.Click += new EventHandler(this.alignSelfBtn_Click);
alignForm.Controls.Add(alignSelfBtn);
TextBox alignContentVal = new TextBox();
alignContentVal.Location = new System.Drawing.Point(139, 10);
alignContentVal.Name = "alignContentVal";
alignContentVal.Size = new System.Drawing.Size(87, 20);
alignContentVal.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
alignForm.Controls.Add(alignContentVal);
TextBox alignItemsVal = new TextBox();
alignItemsVal.Location = new System.Drawing.Point(139, 45);
alignItemsVal.Name = "alignItemsVal";
alignItemsVal.Size = new System.Drawing.Size(87, 20);
alignItemsVal.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
alignForm.Controls.Add(alignItemsVal);
TextBox alignSelfval = new TextBox();
alignSelfval.Location = new System.Drawing.Point(139, 79);
alignSelfval.Name = "alignSelfval";
alignSelfval.Size = new System.Drawing.Size(87, 20);
alignSelfval.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
alignForm.Controls.Add(alignSelfval);
}
private void alignContentBtn_Click(object sender, EventArgs e)
{
ComboBox c1 = new ComboBox();
c1.Name = "c1";
c1.Size = new Size(80, 21);
c1.Location = new Point(12, 38);
c1.Items.AddRange(new object[] {
"flex-start",
"flex-end",
"center",
"space-between",
"space-around",
"stretch"});
c1.SelectedIndexChanged += new System.EventHandler(this.c1_SelectedIndexChanged);
alignC.Controls.Add(c1);
Button aOk = new Button();
aOk.Location = new System.Drawing.Point(99, 86);
aOk.Size = new System.Drawing.Size(40, 23);
aOk.Text = "OK";
aOk.Click += new EventHandler(this.aOk_Click);
alignC.Controls.Add(aOk);
}