用c#写一个窗体注册界面,用户登录要求输入用户名,密码,确认密码,用户名和密码不能为空,当输入密码不一致时,要求重新输入
时间: 2024-02-07 08:06:16 浏览: 24
好的,以下是一个简单的 C# 窗体注册界面的实现:
```csharp
using System;
using System.Windows.Forms;
namespace RegisterForm
{
public partial class RegisterForm : Form
{
public RegisterForm()
{
InitializeComponent();
}
private void btnRegister_Click(object sender, EventArgs e)
{
string username = txtUsername.Text.Trim();
string password = txtPassword.Text.Trim();
string confirmPassword = txtConfirmPassword.Text.Trim();
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(confirmPassword))
{
MessageBox.Show("用户名和密码不能为空!");
return;
}
if (password != confirmPassword)
{
MessageBox.Show("两次输入的密码不一致,请重新输入!");
txtPassword.Text = "";
txtConfirmPassword.Text = "";
return;
}
// 注册成功,可以保存用户名和密码到数据库中
MessageBox.Show("注册成功!");
}
}
}
```
在窗体设计器中添加三个文本框和一个按钮,分别对应用户名、密码、确认密码和注册按钮。然后在代码中实现按钮的 Click 事件处理函数,获取文本框中的输入,并进行校验。如果用户名和密码为空,弹出提示框;如果两次输入的密码不一致,也弹出提示框,并清空密码文本框,让用户重新输入;如果一切校验通过,就可以将用户名和密码保存到数据库中,这里没有实现具体的数据库操作,只是演示了一个简单的注册流程。