我按照书上创建一个Solution,里面有两个项目,一个是类库叫ClassLibrary1,一个是应用程序,叫WindowsApplication1,(都是默认的名字)
然后我把ClassLibrary1加到WindowsApplication1的引用里面,
ClassLibrary1中有个窗体叫frmClass,frmClass里面有个编辑框叫 txtBox;
WindowsApplication1里面的一个按纽事件代码如下:
ClassLibrary1.frmClass frm=new ClassLibrary1.frmClass();
frm.ShowDialog();
string a=frm.txtBox.Text;
其中最后一句有错误,说 我txtBox没有定义,可是我明明定义了呀,那个窗体可以new出来,可是里面的数据怎么传不过来 呀;
然后我把ClassLibrary1加到WindowsApplication1的引用里面,
ClassLibrary1中有个窗体叫frmClass,frmClass里面有个编辑框叫 txtBox;
WindowsApplication1里面的一个按纽事件代码如下:
ClassLibrary1.frmClass frm=new ClassLibrary1.frmClass();
frm.ShowDialog();
string a=frm.txtBox.Text;
其中最后一句有错误,说 我txtBox没有定义,可是我明明定义了呀,那个窗体可以new出来,可是里面的数据怎么传不过来 呀;
public string Text
{
get{return this.txtBox.Text;}
}
这样就可以了.
下面是我测试的,没问题:
ClassLibrary1.Form1 f1 = new ClassLibrary1.Form1();
f1.ShowDialog();
MessageBox.Show(f1.textBox1.Text.ToString());