我有windows-mobile程序,有两种形式。
在form1中,我有TextBox,在form2中,我有5个按钮。
当我按下form2中的按钮我会在form1的文本框中看到它们时如何做到这一点
答案 0 :(得分:1)
在表单上创建一个公共属性,允许调用表单访问所选值。
public partial class SelectionForm : Form
{
public SelectionForm()
{
InitializeComponent();
}
//Selection holder
private string _selection;
//Public access to this item
public string Selection { get { return _selection; } }
private void button1_Click(object sender, EventArgs e)
{
_selection = "One was selected";
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
_selection = "Two was selected";
this.Close();
}
}
然后,从您的调用表单中,您可以在表单处理之前获取此值。
public partial class TextForm : Form
{
public TextForm()
{
InitializeComponent();
}
private void btnSelect_Click(object sender, EventArgs e)
{
using (SelectionForm selectionForm = new SelectionForm())
{
selectionForm.ShowDialog();
txtSelection.Text = selectionForm.Selection;
}
}
}