如何带参数打开另外一个窗体???

songyawei 2003-07-23 08:47:10
在用户登录系统以后,想把用户的ID传到frmMain中,请问我该怎么作???
...全文
40 6 打赏 收藏 举报
写回复
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
SimonSnow 2003-07-23
  • 打赏
  • 举报
回复
一种办法:
在登录窗体中设置公有变量或属性(或干脆用Tag属性):
public string id;
登录正确时将ID赋值给id,关闭窗体。

在主窗体中:
LoginForm log=new LoginForm();
log.ShowDialog();
string userID=log.id;
...
seabirdforever 2003-07-23
  • 打赏
  • 举报
回复
在form1.cs中

string s1,s2;
......

Form2 newform = Form2( s1,s2);
newform.Show();

在form2.cs中

class Form2
{
public Form2(string s1,string s2) //主要是构造函数
{
//初始化 code.....
}
// other code
}
yaohangnet 2003-07-23
  • 打赏
  • 举报
回复
在frmMain中声明变量 Public string uesrID;

在frmMain中
F_login login=new F_login()
login.showdialog();
uesrID=login.txtUserID.Text; *(txtUserID 的 modifiers 设为 Public);
nchln 2003-07-23
  • 打赏
  • 举报
回复
在frmMain的构造函数重载一个带参数的就行了,或者在frmMain中作一个public的方法,在登录窗口调用该方法,将参数传过去
songyawei 2003-07-23
  • 打赏
  • 举报
回复
是在winform中,在aspx中我也会作
latahu 2003-07-23
  • 打赏
  • 举报
回复
// 保存用户名,进入系统
FormsAuthentication.SetAuthCookie(txtUserID.Value, false);
this.Response.Redirect("index.htm", true);
得到用户ID
strUserID=User.Identity.Name;
相关推荐
发帖
C#

10.9w+

社区成员

.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
帖子事件
创建了帖子
2003-07-23 08:47
社区公告

让您成为最强悍的C#开发者