WinForm窗体传值的一个方法

功能类
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;
}
}

你可能感兴趣的:(C#/.Net)