我想让两个页面跳转 一个是注册页面 一个是登录页面,想的是让用户注册完后 点确定按钮 系统提示执行成功 后跳转到登录页面,我在注册页面的【确定】按钮下 写的是判断密码之类的语句 另外 还有个自定义方法 用来保存用户的信息。窗体跳转 我写的代码是
LoginForm loginform = new LoginForm();
loginform.Show();
关闭是
this.Close(); 可就是出不来效果 问老师吧 说是我的 this有问题 也不告诉解决方法 还让我去重新写代码 这不是折磨我啊 所以 才发帖 求助!!! 先谢谢啦!
LoginForm loginform = new LoginForm();
loginform.Show();
关闭是
this.Close(); 可就是出不来效果 问老师吧 说是我的 this有问题 也不告诉解决方法 还让我去重新写代码 这不是折磨我啊 所以 才发帖 求助!!! 先谢谢啦!
可以用this.hide()把注册页面隐藏了
登陆窗口写
private void F1button1_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
this.Close();
}
Program.cs里写
static void Main()
{
Login F1 = new Login();
F1.ShowDialog();
if(open.DialogResult==DialogResult.OK)
Application.Run(new F2());
else return;
}
注册信息传参就好啦
public partial class RegisterForm : Form
{
//定义共有的静态变量保存用户注册的头像图片所以
public static int r_PicID = 0;
public RegisterForm()
{
InitializeComponent();
}
//>>图片按钮事件
private void picSelectFace_Click(object sender, EventArgs e)
{
//创建选择头像窗体
FaceForm faceForm = new FaceForm();
//已模式窗体方式打开
faceForm.ShowDialog();
//设置图片的控件图片是图片列表控件中的索引所在图片
picFace.Image = ilFace.Images[r_PicID];
} //确定按钮事件
private void btnRegister_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
this.Close(); //判断注册信息是否为空
if (txtUser.Text.Trim() == "" || txtPwd.Text.Trim() == "" || txtPwdAgain.Text.Trim() == "")
{
MessageBox.Show("请输入完整的注册信息!");
return;
}
//判断用户名是否符合要求
if (txtUser.Text.Trim().Length < 1 || txtUser.Text.Trim().Length > 10)
{
MessageBox.Show("用户名应为1—10位!");//提示错误消息
return;
}
//判断密码是否符合要求
if (txtPwd.Text.Trim().Length < 6 || txtPwd.Text.Trim().Length > 10)
{
MessageBox.Show("密码应为6—10位!");//提示错误消息
return;
}
//判断确认密码是否符合要求
if (txtPwdAgain.Text.Trim().Length < 6 || txtPwdAgain.Text.Trim().Length > 10)
{
MessageBox.Show("确认密码错误!应为6—10位!");//提示错误消息
return;
}
//判断两个输入密码是否相同
if (txtPwd.Text.Trim() != txtPwdAgain.Text.Trim())
{
MessageBox.Show("请输入正确的密码!");
return;
}
//调用自定义方法
Register();
} //自定义方法注册用户
private void Register()
{
//保存此用户是否是否已存在的sql语句
string strsql = "select count(*) from Users where UName='" + txtUser.Text.Trim() + "'";
try//异常处理
{
//创建command的对象
SqlCommand com = new SqlCommand(strsql, DBHelp.con);
//打开连接
DBHelp.con.Open();
//执行查询
int count = (int)com.ExecuteScalar();
if (count > 0) //判断此用户是否存在
{
//若存在提示信息
MessageBox.Show("此用户名已存在,请重新输入用户名!");
return;//停止注册
}
//如果此用户不存在保存注册信息
string name = txtUser.Text.Trim();//用户名
string pwd = txtPwd.Text.Trim();//密码
string sex = "男";//性别
if (rdoWoman.Checked == true)
{
sex = "女";
}
//给command对象的执行语句重新复制
com.CommandText = "insert into Users values('" + name + "','" + pwd + "','"+sex+"'," +r_PicID + ",0)";
count = com.ExecuteNonQuery();//执行插入
if (count > 0)//判断插入是否成功
{
MessageBox.Show("执行成功!");//成功提示
}
else
{
MessageBox.Show("注册失败,请重新注册!");//失败提示
}
}
catch
{
MessageBox.Show("注册失败,请重新注册!");
}
finally
{
//判断连接对象的状态是否打开
if (DBHelp.con.State == ConnectionState.Open)
{
DBHelp.con.Close();//关闭连接对象
}
}
}
//取消按钮事件
private void btnCancel_Click(object sender, EventArgs e)
{
MessageBox.Show("您是否取消注册?");//提示是否取取消事件
this.Close();//关闭窗体
}
这是我的注册RegisterForm窗体中的代码 想跳到LoginFrom 登录窗体 谁能告诉我需要添加在什么地方添加什么代码才能实现跳转和RegisterForm窗体关闭啊?!