我写了一个C#的程序,打开时主窗口中默认打开一个子窗口,想要打开其他窗口并把已经打开的所有子窗口关闭,怎么操作啊?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
首先 在解决方案管理器(Program.cs)里的代码


[csharp] http://blog.csdn.net/qq520360/article/details/7524234#" title="view plain
view plain http://blog.csdn.net/qq520360/article/details/7524234#" title="copy copy http://blog.csdn.net/qq520360/article/details/7524234#" title="print print http://blog.csdn.net/qq520360/article/details/7524234#" title="? ?

<ol>
<span>static <span>void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(<span>false); Form Login = <span>new Login(); Login.ShowDialog();<span>//显示登陆窗体 <span>if (Login.DialogResult == DialogResult.OK) Application.Run(<span>new Main());<span>//判断登陆成功时主进程显示主窗口
<span>else <span>return; } </ol>

<textarea class="csharp" name="code" readonly="readonly" style="display:none; static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Form Login = new Login(); Login.ShowDialog();//显示登陆窗体 if (Login.DialogResult
== DialogResult.OK) Application.Run(new Main());//判断登陆成功时主进程显示主窗口 else return; }</textarea>
然后 在登陆窗口(Login.cs)的登陆按钮(BTLogin)Click事件里:


[csharp] http://blog.csdn.net/qq520360/article/details/7524234#" title="view plain
view plain http://blog.csdn.net/qq520360/article/details/7524234#" title="copy copy http://blog.csdn.net/qq520360/article/details/7524234#" title="print print http://blog.csdn.net/qq520360/article/details/7524234#" title="? ?

<ol>
<span>private <span>void BTLogin_Click(<span>object sender, EventArgs e) { <span>if (TBUserName.Text == <span>"www.520360.com" && TBPassWord.Text == <span>"123") { <span>this.DialogResult = DialogResult.OK;<span>//关键:设置登陆成功状态
<span>this.Close(); } <span>else { MessageBox.Show(<span>"账号或密码错误,请重试"); } } </ol>


View the full article
 
Back
Top