Files
aiData/WordAddIn/WordAddIn/LoginForm.cs
HuangHai 2c336a0635 'commit'
2026-01-24 18:05:24 +08:00

158 lines
6.8 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;
private Label lblTitle;
private Label lblUser;
private Label lblPass;
public LoginForm()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.lblTitle = new System.Windows.Forms.Label();
this.lblUser = new System.Windows.Forms.Label();
this.txtUsername = new System.Windows.Forms.TextBox();
this.lblPass = new System.Windows.Forms.Label();
this.txtPassword = new System.Windows.Forms.TextBox();
this.btnLogin = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// lblTitle
//
this.lblTitle.AutoSize = false;
this.lblTitle.Font = new System.Drawing.Font("微软雅黑", 16F, System.Drawing.FontStyle.Bold);
this.lblTitle.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(43)))), ((int)(((byte)(87)))), ((int)(((byte)(154)))));
this.lblTitle.Location = new System.Drawing.Point(0, 25);
this.lblTitle.Name = "lblTitle";
this.lblTitle.Size = new System.Drawing.Size(500, 40);
this.lblTitle.TabIndex = 0;
this.lblTitle.Text = "AI助手";
this.lblTitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// lblUser
//
this.lblUser.AutoSize = true;
this.lblUser.Font = new System.Drawing.Font("微软雅黑", 11F);
this.lblUser.Location = new System.Drawing.Point(80, 85);
this.lblUser.Name = "lblUser";
this.lblUser.Size = new System.Drawing.Size(63, 20);
this.lblUser.TabIndex = 1;
this.lblUser.Text = "用户名:";
//
// txtUsername
//
this.txtUsername.Font = new System.Drawing.Font("微软雅黑", 11F);
this.txtUsername.Location = new System.Drawing.Point(160, 80);
this.txtUsername.Name = "txtUsername";
this.txtUsername.Size = new System.Drawing.Size(220, 27);
this.txtUsername.TabIndex = 2;
this.txtUsername.Text = "huanghai";
//
// lblPass
//
this.lblPass.AutoSize = true;
this.lblPass.Font = new System.Drawing.Font("微软雅黑", 11F);
this.lblPass.Location = new System.Drawing.Point(80, 145);
this.lblPass.Name = "lblPass";
this.lblPass.Size = new System.Drawing.Size(58, 20);
this.lblPass.TabIndex = 3;
this.lblPass.Text = "密 码:";
//
// txtPassword
//
this.txtPassword.Font = new System.Drawing.Font("微软雅黑", 11F);
this.txtPassword.Location = new System.Drawing.Point(160, 140);
this.txtPassword.Name = "txtPassword";
this.txtPassword.PasswordChar = '●';
this.txtPassword.Size = new System.Drawing.Size(220, 27);
this.txtPassword.TabIndex = 4;
this.txtPassword.Text = "12345678";
//
// btnLogin
//
this.btnLogin.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(43)))), ((int)(((byte)(87)))), ((int)(((byte)(154)))));
this.btnLogin.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnLogin.FlatAppearance.BorderSize = 0;
this.btnLogin.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnLogin.Font = new System.Drawing.Font("微软雅黑", 10F, System.Drawing.FontStyle.Bold);
this.btnLogin.ForeColor = System.Drawing.Color.White;
this.btnLogin.Location = new System.Drawing.Point(110, 220);
this.btnLogin.Name = "btnLogin";
this.btnLogin.Size = new System.Drawing.Size(120, 40);
this.btnLogin.TabIndex = 5;
this.btnLogin.Text = "立即登录";
this.btnLogin.UseVisualStyleBackColor = false;
this.btnLogin.Click += new System.EventHandler(this.BtnLogin_Click);
//
// btnCancel
//
this.btnCancel.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Font = new System.Drawing.Font("微软雅黑", 10F);
this.btnCancel.Location = new System.Drawing.Point(250, 220);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(120, 40);
this.btnCancel.TabIndex = 6;
this.btnCancel.Text = "取消";
this.btnCancel.UseVisualStyleBackColor = true;
//
// LoginForm
//
this.AcceptButton = this.btnLogin;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.CancelButton = this.btnCancel;
this.ClientSize = new System.Drawing.Size(500, 320);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnLogin);
this.Controls.Add(this.txtPassword);
this.Controls.Add(this.lblPass);
this.Controls.Add(this.txtUsername);
this.Controls.Add(this.lblUser);
this.Controls.Add(this.lblTitle);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "LoginForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "AI助手 - 用户登录";
this.ResumeLayout(false);
this.PerformLayout();
}
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();
}
}
}
}