如何将字符串从一个窗体传递到另一个窗体用于Visual C# [英] How to pass string from one form to another form for Visual C#

查看:236
本文介绍了如何将字符串从一个窗体传递到另一个窗体用于Visual C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。这是问题



表格2

Hello. Here is the problem

Form 2

 private string data;

private void btnOK_Click(object sender, EventArgs e)
        {
            data=txtDB.Text; //set data
            this.Hide();
        }

        public string getData()
        {
            return data;
        }





表格1



Form 1

Form2 frm = new Form2();
string data = frm.getData(); //get data from Form2
 MessageBox.Show(data);







消息框为空。如何确保数据传递




The messagebox is empty. How to make sure the data is passing

推荐答案

访问此处...



http://www.c- sharpcorner.com/forums/thread/154204/how-to-pass-a-string-from-one-form-to-another.aspx [ ^ ]
visit here...

http://www.c-sharpcorner.com/forums/thread/154204/how-to-pass-a-string-from-one-form-to-another.aspx[^]


public static string str="";

       private void button1_Click(object sender, EventArgs e)
       {
           str = textBox1.Text;
           
           this.Hide();

       }
       public string getdata()
       {
           return str;
       }





form2



form2

Form1 f = new Form1();
           label1.Text =f.getdata();


使用静态属性getData创建一个类并设置值。然后,您将能够在应用程序
Create a Class with Static property getData and set the value. Then you will be able to access this value any where in the application


这篇关于如何将字符串从一个窗体传递到另一个窗体用于Visual C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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