主窗口A点击button1,弹出一个Form B,B仅有唯一实例。要在B中能获取A的所有数据,B类该怎么写?又如何调用呢?
A中有一个datagridview,datasource是一个自定义类型的LIST.
之前B类我是这么写的: public partial class B: Form //单件模式
{
private static B instance=null;
public B()
{
InitializeComponent();
this.comboBox1.SelectedIndex = 0;
}
public static B Instance
{
get
{
if (instance == null) instance = new B();
return instance;
}
}调用的时候直接访问静态的instance,关闭时设为null。
为了获取A的List,我也改为静态的,能获取到,但是发现没发得到A的Left和Top,更没办法对他操作了。
程序在单线程模式下,单件可以稍微简单点。
请各位帮帮忙先谢过大家。。
A中有一个datagridview,datasource是一个自定义类型的LIST.
之前B类我是这么写的: public partial class B: Form //单件模式
{
private static B instance=null;
public B()
{
InitializeComponent();
this.comboBox1.SelectedIndex = 0;
}
public static B Instance
{
get
{
if (instance == null) instance = new B();
return instance;
}
}调用的时候直接访问静态的instance,关闭时设为null。
为了获取A的List,我也改为静态的,能获取到,但是发现没发得到A的Left和Top,更没办法对他操作了。
程序在单线程模式下,单件可以稍微简单点。
请各位帮帮忙先谢过大家。。
///A 是否 public
public static B Instance(A)
{
if (instance == null) instance = new B();
B.a = A;
return instance;
}