最好的方式来处理合格Control.Checked国家形式之间 [英] Best way to handle passing of Control.Checked state between forms

查看:86
本文介绍了最好的方式来处理合格Control.Checked国家形式之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它,因为我已经与Windows合作了一段时间Forms应用程序。我的主要形式,并根据一定的条件对一个复选框,如果第二个表需要打开从用户请求额外的数据,我应该怎么传递(或获得)一条讯息从第二主表表格,以便我可以告诉它是否没关系选中或清除该复选框?

It's been a while since I've worked with Windows Forms applications. I have a Checkbox on the Main form and, based upon a certain condition, if the Second form needs to be opened to request additional data from the user, how should I pass (or get) back a message to the Main form from the Second form so I can tell whether or not it's okay to Check or Uncheck the Checkbox?

从我记事起,我可以使用类似路过 REF 。还是有更好的方法来做到这一点?

From what I can remember, I could use something like Pass by ref. Or is there a better way to accomplish this?

推荐答案

要做到这一点是使用一个事件的一种方式。

One way to do this would be to use an event.

在你的孩子的形式,宣布任何事件上的特定用户交互待提高,并简单地订阅此事件在您的主要形式。

In your child form, declare an event to be raised upon specific user interaction, and simply "subscribe" to this event in your main form.

当你实例化并打电话给你的孩子的形式,你会做这样的:

When you instantiate and call you child form, you'd do like this:

private void button1_Click(object sender, EventArgs e)
{
    Form2 frm = new Form2();
    frm.MyEvent += frm_MyEvent;
    frm.ShowDialog();
    frm.MyEvent -= frm_MyEvent;
}

private void frm_MyEvent(object sender, EventArgs e)
{
    textBox1.Text = "whatever"; //just for demo purposes
}

在你的孩子的形式,你声明的情况下,提高它:

In your child form, you declare the event and raise it:

public event EventHandler MyEvent;

private void button1_Click(object sender, EventArgs e)
{
    if (MyEvent!= null)
        MyEvent(this, EventArgs.Empty);
}

希望这有助于

Hope this helps

这篇关于最好的方式来处理合格Control.Checked国家形式之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆