如何显示从form1到form3的多个值

时间:2015-09-27 05:43:14

标签: c# forms winforms

我是C#的新手,我希望将form1中的textBox1,textBox2和textBox3的值显示为表单3中的我的标签。但它只显示空格。有人可以告诉我该怎么做吗?

PIC:

5 个答案:

答案 0 :(得分:1)

您可以在表单1中单击按钮

执行此操作
 private void btnTransfer_Click(object sender, EventArgs e)
        {
            Form3 frmdisplay = new Form3(txtFirstName.Text.ToString(), txtSecondName.Text.ToString(), txtPay.Text.ToString());
            frmdisplay.Show();
        }

并在表格3中显示如下,

 public Form3(string Firstname,string Lastname ,string Pay)
        {
            InitializeComponent();
            lblName.Text = "Your name is" + Firstname +" "+ Lastname ;
            lblPayment.Text = "Your payment is" + Pay;

        }

答案 1 :(得分:0)

假设您在Form1按下"表单2"之后尝试将数据加载到Form3中。按钮,你需要:  1.为控件命名  2.将Form3控件设置为与Form1

中相同的值

使用您的名字猜测的示例(因为您没有发布任何代码):

var resultDialog = new Form3();
resultDialog.lblFullName.Text = this.txtFirstName.Text + " " + this.txtLastName.Text;
resultDialog.lblPayment.Text = this.txtPayment.Text;

答案 2 :(得分:0)

在Form1类代码中

private void form2btn_Click(object sender, EventArgs e)
{
    Form form2 = new Form2(FirstName.Text + " " + SecondName.Text, Pay.Text);
    form2.ShowDialog();
}

你的Form2类代码:

public class Form2 : Form
{
    public Form2(string name , string pay)
    {
        Form form3 = new Form3(name, pay);
        form3.ShowDialog();
    }
}

你的Form3类代码:

public class Form3 : Form
{   
    public Form3(string name , string pay)
    {
        NameTextBlock.Text = name;
        PayTextBlock.Text = pay;
    }

}

答案 3 :(得分:0)

From3

    public void Message(string firstname, string lastname, string pay)
    {
        lblName.Text = "Your name is" + firstname + " " + lastname;
        lblPayment.Text = "Your payment is" + pay;
    }

From1

        public Form1()
        {
            InitializeComponent();
        }

        public delegate void SendMessage(string Firstname, string Lastname,string Pay);
        public event SendMessage OnSendMessage;

        private void button1_Click(object sender, EventArgs e)
        {
            Form3 from3 = new Form3();
            OnSendMessage += from3.Message;
            OnSendMessage(Firstname.Text, Lastname.Text, Pay.Text);
            from3.Show(); 
        }

答案 4 :(得分:0)

步骤1:在form2中添加属性以设置标签'text

public string Name
 {
      set{label1.Text=value;}
 } 

步骤2:在form1的按钮单击事件处理程序中添加以下代码。

private void button1_Click(object sender, System.EventArgs e)          
 {
      Form2 frm=new Form2();
      frm.Name=txt1.text;
      frm.Show();
 }           

您可以根据需要添加属性