如何从一个窗体到另一个

xisimao 2009-05-15 07:35:52
简单做了个登陆的,点击确定后我使用了下面代码进入下一个窗体

Main m = new Main(txtName.Text);
m.Show();
this.Close()

但是发现两个窗体都没了,如何让第二个窗体不自动关闭呢?我原来一直把两个窗体都放在一个父窗体的框架内做,请问除此之外还有别的方法么?谢谢指教!
...全文
83 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
ljb07976513524 2009-05-15
  • 打赏
  • 举报
回复
this.Hide();隐藏窗体
聖少俊 2009-05-15
  • 打赏
  • 举报
回复
还可以这样 this.Visible = false;
potato-pyy 2009-05-15
  • 打赏
  • 举报
回复
Main m = new Main(txtName.Text);
this.Close();
m.Show();
wuyq11 2009-05-15
  • 打赏
  • 举报
回复
Form2 f2 = new Form2();
f2.ShowDialog();
//在f2的窗体弹出以后,将在f2窗体上进行操作,Form1暂时被限制操作,如果弹出的f2关闭,将弹出下面的对话框
MessageBox.Show("f2已经关闭!");
}
而如果是下面的方法
private void TestShow()
{
Form2 f2 = new Form2();
f2.Show();
//在f2的窗体弹出以后,将接着弹出下面,Form1和新弹出的f2可以同时存在,并随便操作哪个窗体,f2关闭以后也不会对Form1产生什么影响,
MessageBox.Show("f2尚未关闭!");
wuyq11 2009-05-15
  • 打赏
  • 举报
回复
Main m = new Main(txtName.Text);
m.Show();
this.Hide();隐藏窗体

yuan1238 2009-05-15
  • 打赏
  • 举报
回复
哇!楼主的问题和我的一样啊!!
我的解决了,我把我的答案分享下吧!!
http://topic.csdn.net/u/20090515/15/92d7b541-f624-4115-a759-680ba3da546d.html
zhensoft163 2009-05-15
  • 打赏
  • 举报
回复
Main m = new Main(txtName.Text);
m.Show();
this.Hide();//隐藏
wangbm 2009-05-15
  • 打赏
  • 举报
回复
登陆和启用主窗体:
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
////Pub.cn = new SqlConnection() ;
////Pub.cmd = new SqlCommand();
////Application.EnableVisualStyles();
////Application.SetCompatibleTextRenderingDefault(false);
////Application.Run(new FrmMain());

Process p = SingleInstance.GetRunningInstance();
if (p != null) //已经有应用程序副本执行
{
SingleInstance.HandleRunningInstance(p);
}
else //启动第一个应用程序
{
RunApplication();
}



}
//启动应用程序
static void RunApplication()
{
//读取配置文件
Pub.strSqlCn = Pub.GetSqlServerConnectString();
//Pub.strSqlCn = "";
Application.EnableVisualStyles();
//Application.Run(new FrmMain());
ReLogin:
try
{

FrmLogin.FrmLogin frmL = new FrmLogin.FrmLogin ();
DialogResult sr = frmL.ShowDialog();
if (sr == DialogResult.OK)
{
frmL.Dispose();
FrmMain frm = new FrmMain();
Application.Run(frm);
//Application.Run(new FrmMain());
DialogResult dr = frm.DialogResult;
frm.Dispose();
if (dr == DialogResult.Retry)
{
goto ReLogin;
}
}
else
{
frmL.Dispose();
}

}
catch (Exception ex)
{
Trace.WriteLine(ex.Message);
}
}


}
wangbm 2009-05-15
  • 打赏
  • 举报
回复
如果你把主窗体关了,子窗体就没了,这样是正常的呀

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

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

试试用AI创作助手写篇文章吧