如何将点击从表单发送到表单

发布于 2024-11-24 11:55:48 字数 133 浏览 0 评论 0原文

我有 Windows 移动程序,有 2 种形式。

在 form1 中,我有 TextBox,在 form2 中,我有 5 个按钮。

如何做到这一点,当我按下 form2 中的按钮时,我会在 form1 的文本框中看到它们

i have windows-mobile program that has 2 forms.

in form1, 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

菩提树下叶撕阳。 2024-12-01 11:55:48

在表单上创建一个公共属性,允许调用表单访问所选值。

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

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;
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文