我有一个showForm
按钮编程创建并打开一个新的form2
与4个DomainUpDown
元件和OKBtn
按钮Form1中。我需要通过我的OKBtn
从form2
到form1
richtextbox将DomainUpDown
元素的值传递给我。我唯一的区别在于最后的问号。以下是代码片段:从程序生成形式传递DomainUpDown.Value到主要形式
public void showForm_Click(object sender,EventArgs e)
{
Form frm = new Form();
frm.Size = new Size(264, 183);
frm.Name = "MarginSelector";
frm.Text = "Qiymət ver";
frm.ShowIcon = false;
frm.Show();
DomainUpDown marginRightVal = new DomainUpDown();
marginRightVal.Location = new Point(150, 100);
marginRightVal.Size = new Size(42, 40);
frm.Controls.Add(marginRightVal);
for (int i = 0; i < 100; i++)
{
marginRightVal.Items.Add(i + "%");
}
Button OKBtn = new Button();
OKBtn.Visible = true;
OKBtn.Text = "OK";
OKBtn.Size = new Size(30, 23);
OKBtn.Location = new Point(96, 109);
frm.Controls.Add(OKBtn);
OKBtn.Click += new System.EventHandler(this.OKBtn_Click);
}
public void OKBtn_Click(object sender, EventArgs e)
{
textArea.SelectionLength = 0;
textArea.SelectedText = string.Filter("margin-top: {0} ; \n, ? ");
}
您需要将'marginRightVal'变量声明移到该方法的外部,以便您还可以在OKBtn_Click事件处理函数中使用它。或者使用lambda表达式。 –