C#编写登陆窗体
要实现教师,管理员,学生登陆··········救救我···我是初学者··
FormLogin.cs//登录窗体
(参考)
C# code
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace SnKsxs//你的名字,呵呵
{
public partial class FormLogin : Form
{
public FormLogin()
{
InitializeComponent();
}
private void btnLogin_Click(object sender, EventArgs e)
{
if (txtUserName.Text=="aaa"&txtPassword.Text=="bbb")//举例的,没有使用数据库
{
ValueClass.LoginUserName = txtUserName.Text;
this.DialogResult = DialogResult.OK;
}
else
{
MessageBox.Show("用户名或密码错误!", "出错啦~~", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtPassword.Focus();
return;
}
return;
}
private void btnCancel_Click(object sender, EventArgs e)
{
Application.ExitThread();
}
}
}
FormMain.cs//程序主窗体
C# code
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace SnKsxs
{
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
}
private void FormMain_Load(object sender, EventArgs e)
{
label1.Text = ValueClass.LoginUserName;
}
}
}
Program.cs
C# code
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace SnKsxs
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new FormLogin());
FormLogin log = new FormLogin();
if (log.ShowDialog() == DialogResult.OK)
Application.Run(new FormMain());
}
}
}
ValueClass.cs//用于传值
C# code
using System;
using System.Collections.Generic;
using System.Text;
namespace SnKsxs
{
class ValueClass
{
public static string LoginUserName = string.Empty;
}
}