您的位置:首页 > 其它

WinForm窗体传值的一个方法

2013-06-27 11:19 316 查看
功能类

public sealed class Setting
{
private static volatile Setting instance;
private static object syncRoot = new Object();
private Setting() { }
public static Setting Instance
{
get
{
if (instance == null)
{
lock (syncRoot)
{
if (instance == null)
instance = new Setting();
}
}
return instance;
}
}
public string UserID;

}

窗体1:为数据传送者

namespace chuangzhi
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Setting m_set = Setting.Instance;
private void button1_Click(object sender, EventArgs e)
{
string UserID = this.textBox1.Text.Trim();
m_set.UserID = UserID;
receive re = new receive();
re.Show();
}
}
}
窗体2:数据接收者

namespace chuangzhi
{
public partial class receive : Form
{
public receive()
{
InitializeComponent();
}
Setting m_set = Setting.Instance;
private void receive_Load(object sender, EventArgs e)
{
this.textBox1.Text = m_set.UserID;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: