C# WinForm 实体类的Form1窗口赋值后打开Form2窗口在Form2窗口里调用不到值
小弟刚开始学WinForm,不知道这样能用不,高手请帮我看下。userstable.cs代码:publicclassUsersTable{privatestringuna...
小弟刚开始学WinForm,不知道这样能用不,高手请帮我看下。
userstable.cs代码:
public class UsersTable
{
private string uname;
public string Uname
{
get { return uname; }
set { uname = value; }
}
private string username;
public string Username
{
get { return username; }
set { username = value; }
}
public UsersTable(string uname, string username)
{
this.uname = uname;
this.username = username;
}
}
窗口Form1.cs代码:
string uname ="uname";
string username = "username";
UsersTable ut = new UsersTable(uname, username);
Form2 F2= new Form2();
F2.how();
this.Hide();
请问在Form2.cs里怎么能得到userstable的属性值?
textbox1.text=new UsersTable().uname;
textbox2.text=new UsersTable().username; 展开
userstable.cs代码:
public class UsersTable
{
private string uname;
public string Uname
{
get { return uname; }
set { uname = value; }
}
private string username;
public string Username
{
get { return username; }
set { username = value; }
}
public UsersTable(string uname, string username)
{
this.uname = uname;
this.username = username;
}
}
窗口Form1.cs代码:
string uname ="uname";
string username = "username";
UsersTable ut = new UsersTable(uname, username);
Form2 F2= new Form2();
F2.how();
this.Hide();
请问在Form2.cs里怎么能得到userstable的属性值?
textbox1.text=new UsersTable().uname;
textbox2.text=new UsersTable().username; 展开
2个回答
展开全部
form2 中添加UsersTable属性
public UsersTable User{get;set;}
form1中赋值
Form2 F2= new Form2();
F2.User = ut;
F2.Show();
this.Hide();
public UsersTable User{get;set;}
form1中赋值
Form2 F2= new Form2();
F2.User = ut;
F2.Show();
this.Hide();
追问
你好,试用了您的方法,如果userstable.cs不放在类库里,可正常取值,但放类库里后就获取不到值了,还请大神指点
追答
既然放到了别的项目里,只要引用就好了
1,添加项目引用;在界面所在的项目,引用上 "添加引用" 选择你的类库项目;
2,界面项目中,需要用到此类型的代码文件,头部using导入userstable
的命名空间
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询