Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
2表格c#_C#_Windows - Fatal编程技术网

2表格c#

2表格c#,c#,windows,C#,Windows,嗨,我在一个应用程序中有两个表单,我想用一个表单在另一个表单中设置标签,我四处寻找答案,但我没有让它工作。代码: 表格一 public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void uit_Click(object sender, EventArgs e) {

嗨,我在一个应用程序中有两个表单,我想用一个表单在另一个表单中设置标签,我四处寻找答案,但我没有让它工作。代码:

表格一

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void uit_Click(object sender, EventArgs e)
        {
            Form2 frm = new Form2(this);
            frm.Show();
        }

        public string LabelText
        {
            get { return uit.Text; }
            set { uit.Text = value; }
        }

    }
表格2:


有人能解释一下为什么这不起作用吗?

我刚刚构建了它,它工作得很好。我假设您已经将事件连接起来了?

看起来应该可以工作了-到底出了什么问题?哪一点不起作用?我假设你已经试着穿过它,一边走一边检查物体?可能这是个问题:。。。txtmessage.Text=this.mainForm.LabelText。。。this.mainForm.LabelText=txtmessage.Text。。。应该有用。它是以一种方式工作还是不工作?当你在
Form2\u Load
button1\u Click
中设置断点时,调试器会说些什么?关于Form2标签和Form1标签中的值@Blogbeard我不知道出了什么问题,当我单击uit Form2打开时,但是当我编辑txtmessage并单击button1时,uit上的文本不会改变@Ira Rainet,我不知道你的确切意思@iburlakov,首先uit的内容需要加载到txtmessage中谢谢,我从头开始构建它,我说在button1_点击this.txtmessage.Text,现在它可以工作了
public partial class Form2 : Form
{
    private Form1 mainForm = null;
    public Form2(Form callingForm)
    {
        mainForm = callingForm as Form1;
        InitializeComponent();
    }
    private void Form2_Load(object sender, EventArgs e)
    {
        txtmessage.Text = this.mainForm.LabelText;
    }
    public void button1_Click(object sender, EventArgs e)
    {
        this.mainForm.LabelText = txtmessage.Text;
    }
}