开发者

How to send a click from a form to a form

i have windows-mobile program that has 2 forms.

in for开发者_如何学编程m1, i have TextBox and in form2, i have 5 buttons.

how to do that when i press the buttons that in form2 i'll see them on the textbox that in form1


Create a public property on your form that will allow the calling form to access the chosen value.

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();
    }
}

Then from your calling form you can obtain this value before the form is disposed.

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;
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜