在C#表单之间交换/传递值

在C#表单之间交换/传递值,c#,C#,我的代码有问题。它运行良好,没有错误,但我认为是合乎逻辑的。我使用了一个方法PassValue(intid)从另一个中获取值。我已经对它进行了测试,表单正确地交换了值,但是当我使用从其他表单收到的值作为“textbox.text”或“label.text”时,问题就出现了 这是我的密码: namespace MyProgram { public partial class UserProfile : Form { public string empidstr; public Us

我的代码有问题。它运行良好,没有错误,但我认为是合乎逻辑的。我使用了一个方法PassValue(intid)从另一个中获取值。我已经对它进行了测试,表单正确地交换了值,但是当我使用从其他表单收到的值作为“textbox.text”或“label.text”时,问题就出现了

这是我的密码:

namespace MyProgram
{
public partial class UserProfile : Form
{
    public string empidstr;
    public UserProfile()
    {
        InitializeComponent();


    }
    public void PassValue(int id)
    {

        string idstring = Convert.ToString(id);
       // empidlabel.Text = idstring;
        empidstr = idstring;
    }


    private void button2_Click(object sender, EventArgs e)
    {
        empidlabel.Text = empidstr;
    }

    private void UserProfile_Load(object sender, EventArgs e)
    {

    }  
}}

您面临什么问题?在哪里调用PassValue()?如果用户在调用之前单击按钮,则empidstr将为空。您有什么问题?在empidstr=idstring行上放置一个断点;要在单击按钮2之前检查它是否实际发生。