两个Form一个为LoginForm,一个为RegisterForm.
RegisterForm里面有一个btnCancel的按钮。
在btnCancel的Clink事件里写了Application.Exit();
为什么我在RegisterForm里面点击btnCancel,LoginFrom会跟着一起关闭
RegisterForm里面有一个btnCancel的按钮。
在btnCancel的Clink事件里写了Application.Exit();
为什么我在RegisterForm里面点击btnCancel,LoginFrom会跟着一起关闭
换成this.Close();
那LoginForm里面有一个lblRegister标签在他的Clink事件里面我写了
RegisterForm rf = new RegisterForm();
rf.Show();
this.Close();
为什么我点击lblRegister的时候两个窗体都关了。
确认一点我要的是关闭LoginForm,打开RegisterForm
而不是把LoginForm隐藏
LoginForm先出来,验证成功后显示不就好了。
this.Close 是关闭当前窗体
Application.Exit()// 结束了当前进程,
我要的是关闭LoginForm,打开RegisterForm
RegisterForm rf = new RegisterForm();
rf.Show();
this.Close();你这就是这个功能啊!
LoginForm隐藏//this.Hide();
因为主窗口的关闭会导致主线程的消息循环被中止,所以,你应该在LoginForm关闭之前将RegisterForm设置为主窗口。
整个工程退出~this.close()本窗口退出
改成Application.Run(new RegisterForm());
但运行起来还是不对。。希望大家帮我解释我错在哪里了,谢谢了
Main()方法
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.Run(new LoginForm());
LoginForm lf = new LoginForm();
if (lf.DialogResult == DialogResult.OK)
{
Application.Run(new RegisterForm());
lf.Close();
}
}
在LoginForm linkLabel的Click的事件里面
RegisterForm rf = new RegisterForm()
rf.Show();
this.DialogResult = DialogResult.OK;
为什么我点击linkLabel控件会完全没反应
你写的代码就是关闭整个程序的
this.close()
关闭所有了.
this.close()
了,当然都关闭了要用this.close();
private void button1_Click(object sender, EventArgs e)
{
if (comboBox1.Text.Trim() == "") { MessageBox.Show("无效的用户名,请输入用户名!","提示",MessageBoxButtons.OK,MessageBoxIcon.Question); comboBox1.Focus(); return; }
if (textBox1.Text == "") { MessageBox.Show("请输入你的密码后再登陆","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning); textBox1.Focus(); return; }
string uname = Conn.ReturnString(Conn.GetDb, "select uname from t_user where uid='" + comboBox1.Text + "' and upassword ='" + textBox1.Text + "'"); if (uname.Trim()!="")
{
Conn.loginname = uname;
Thread t = new Thread(new ThreadStart(OpenMain));
t.Start();
}
else
{
MessageBox.Show("请输入你的用户名或密码错误,请重新确认", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox1.Focus();
return;
}
} private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
//新增一个线程
private void OpenMain()
{
FormMain main = new FormMain();
main.WindowState = FormWindowState.Maximized;
this.Close();
main.ShowDialog(); }
using System.Collections.Generic;
using System.Windows.Forms;namespace Lay
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); //frmLogin是主窗体
frm = new frmLogin();
while (frm != null)
{
Application.Run(frm);
int nLayer = GC.GetGeneration(frm);
frm = null;
GC.Collect(nLayer);
frm = frmNext;
frmNext = null; } //frm2 = new frmInit();
//while ((frm2 != null && frm==null) || frm2!=null)
//{
// Application.Run(frm2);
// int nLayer2 = GC.GetGeneration(frm2);
// frm2 = null;
// GC.Collect(nLayer2);
// frm2 = frmNext2;
// frmNext2 = null; //}
}
private static Form frm;
public static Form frmNext;
//private static Form frm2;
//public static Form frmNext2; }
}
使用:
Program.frmNext = new frmInit(); //frmInit是你要打开的窗体
this.Close();
02 {
03 Application.EnableVisualStyles();
04 Application.SetCompatibleTextRenderingDefault(false);
05
06 Application.Run(new LoginForm()); -- 这句放这里没有任何意义, LoginForm 为什么要有两个实例
07 LoginForm lf = new LoginForm();
08 if (lf.DialogResult == DialogResult.OK) -- 这句应改为 lf.ShowDialog() == DialogResult.OK
09 {
10 Application.Run(new RegisterForm());
11 lf.Close(); -- 这句可以放在10行前面
12 }
13 }
你在这里的this 不就代表LonginForm的实例吗!!!!!!!!!!!!!!!!!
if (textBox1.Text == "") { MessageBox.Show("请输入你的密码后再登陆","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning); textBox1.Focus(); return; }
string uname = Conn.ReturnString(Conn.GetDb, "select uname from t_user where uid='" + comboBox1.Text + "' and upassword ='" + textBox1.Text + "'"); if (uname.Trim()!="")
{
Conn.loginname = uname;
Thread t = new Thread(new ThreadStart(OpenMain));
t.Start();
}
else
{
MessageBox.Show("请输入你的用户名或密码错误,请重新确认", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox1.Focus();
return;
}
} private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
//新增一个线程
private void OpenMain()
{
FormMain main = new FormMain();
main.WindowState = FormWindowState.Maximized;
this.Close();
main.ShowDialog(); }