Winform不用窗体之间传值
1 先构建一个类,内容如下:
namespace TravelForm { 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 UserName; } }
2 在窗体1中赋值:
Setting m_set = Setting.Instance;
m_set.UserName = "test";
3 在窗体2 中 取值:
Setting m_set = Setting.Instance; string request = m_set.UserName;