ConfigForm.cs 配置窗體
Code
[copy to clipboard]
CODE:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace QQLogin
{
public partial class ConfigForm : Form
{
UserInfo ui;
public ConfigForm()
{
InitializeComponent();
}
private void txtPath_Click(object sender, EventArgs e)
{//點擊一次文本框,彈出一次對話框來選擇QQ路徑
DialogResult dr = this.opfQQ.ShowDialog();
if (dr == DialogResult.OK)
{
this.txtPath.Text = opfQQ.FileName;
}
}
private bool ValidateInput()
{//驗證是否輸入完整
if (this.txtUser.Text == "")
{
this.txtUser.Focus();
return false;
}
else if (this.txtPwd.Text == "")
{
this.txtPwd.Focus();
return false;
}
else if (this.txtPath.Text == "")
{
return false;
}
return true;
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void ConfigForm_Load(object sender, EventArgs e)
{
LoadInfo();
}
private void btnSave_Click(object sender, EventArgs e)
{
ui = new UserInfo();
ui.Username = this.txtUser.Text.Trim();
ui.PassWord = this.txtPwd.Text;
ui.Type = this.cboType.Text == "正常" ? "41" : "40";
ui.Path = this.txtPath.Text;
if (this.ValidateInput())
{
SerializeHelper.SerializeUserInfo(ui);
this.Close();
}
}
private void LoadInfo()
{
ui = SerializeHelper.DeserializeUserInfo();
if (ui != null)
{
this.txtUser.Text = ui.Username;
this.txtPwd.Text = ui.PassWord;
this.cboType.SelectedIndex = ui.Type == "41" ? 0 : 1;
this.txtPath.Text = ui.Path;
}
else
{
this.cboType.SelectedIndex = 0;
}
}
}
}