116 lines
4.1 KiB
C#
116 lines
4.1 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
namespace WordAddIn
|
|
{
|
|
public class LoginForm : Form
|
|
{
|
|
private TextBox txtUsername;
|
|
private TextBox txtPassword;
|
|
private Button btnLogin;
|
|
private Button btnCancel;
|
|
|
|
public LoginForm()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void InitializeComponent()
|
|
{
|
|
this.Text = "AI助手 - 用户登录";
|
|
this.Size = new Size(500, 320); // 增大尺寸
|
|
this.StartPosition = FormStartPosition.CenterScreen;
|
|
this.FormBorderStyle = FormBorderStyle.FixedDialog;
|
|
this.MaximizeBox = false;
|
|
this.MinimizeBox = false;
|
|
this.BackColor = Color.White;
|
|
|
|
// 调整布局参数
|
|
int startY = 80;
|
|
int gapY = 60;
|
|
int labelX = 80;
|
|
int inputX = 160;
|
|
int inputWidth = 220;
|
|
|
|
// 标题区域
|
|
Label lblTitle = new Label
|
|
{
|
|
Text = "教案AI助手",
|
|
Font = new Font("微软雅黑", 16, FontStyle.Bold),
|
|
Location = new Point(0, 25),
|
|
AutoSize = false,
|
|
Width = 500,
|
|
TextAlign = ContentAlignment.MiddleCenter,
|
|
ForeColor = Color.FromArgb(43, 87, 154)
|
|
};
|
|
this.Controls.Add(lblTitle);
|
|
|
|
// 1. 用户名
|
|
var lblUser = new Label { Text = "用户名:", Location = new Point(labelX, startY + 5), AutoSize = true, Font = new Font("微软雅黑", 11) };
|
|
txtUsername = new TextBox { Location = new Point(inputX, startY), Width = inputWidth, Font = new Font("微软雅黑", 11), Text = "huanghai" };
|
|
|
|
// 2. 密码
|
|
var lblPass = new Label { Text = "密 码:", Location = new Point(labelX, startY + gapY + 5), AutoSize = true, Font = new Font("微软雅黑", 11) };
|
|
txtPassword = new TextBox { Location = new Point(inputX, startY + gapY), Width = inputWidth, Font = new Font("微软雅黑", 11), PasswordChar = '●', Text = "12345678" };
|
|
|
|
// Buttons
|
|
btnLogin = new Button
|
|
{
|
|
Text = "立即登录",
|
|
Location = new Point(110, 220),
|
|
Width = 120,
|
|
Height = 40,
|
|
BackColor = Color.FromArgb(43, 87, 154),
|
|
ForeColor = Color.White,
|
|
FlatStyle = FlatStyle.Flat,
|
|
DialogResult = DialogResult.None,
|
|
Font = new Font("微软雅黑", 10, FontStyle.Bold),
|
|
Cursor = Cursors.Hand
|
|
};
|
|
btnLogin.FlatAppearance.BorderSize = 0;
|
|
btnLogin.Click += BtnLogin_Click;
|
|
|
|
btnCancel = new Button
|
|
{
|
|
Text = "取消",
|
|
Location = new Point(250, 220),
|
|
Width = 120,
|
|
Height = 40,
|
|
DialogResult = DialogResult.Cancel,
|
|
Font = new Font("微软雅黑", 10),
|
|
Cursor = Cursors.Hand
|
|
};
|
|
|
|
this.Controls.Add(lblUser);
|
|
this.Controls.Add(txtUsername);
|
|
this.Controls.Add(lblPass);
|
|
this.Controls.Add(txtPassword);
|
|
this.Controls.Add(btnLogin);
|
|
this.Controls.Add(btnCancel);
|
|
|
|
this.AcceptButton = btnLogin;
|
|
this.CancelButton = btnCancel;
|
|
}
|
|
|
|
private void BtnLogin_Click(object sender, EventArgs e)
|
|
{
|
|
string user = txtUsername.Text.Trim();
|
|
string pass = txtPassword.Text.Trim();
|
|
|
|
// 模拟验证逻辑
|
|
if (user == "huanghai" && pass == "12345678")
|
|
{
|
|
this.DialogResult = DialogResult.OK;
|
|
this.Close();
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("用户名或密码错误!\n(默认账号: huanghai, 密码: 12345678)", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
txtPassword.Focus();
|
|
txtPassword.SelectAll();
|
|
}
|
|
}
|
|
}
|
|
}
|