在网络上,二进制文件容易加密,且传输快.有些其它文件不可比的好处,
窗体设计文档
namespace EmployeeManagementSystem
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.lblName = new System.Windows.Forms.Label();
this.lblGender = new System.Windows.Forms.Label();
this.lblAge = new System.Windows.Forms.Label();
this.lblSalary = new System.Windows.Forms.Label();
this.lblMB = new System.Windows.Forms.Label();
this.lblIsMarried = new System.Windows.Forms.Label();
this.txtName = new System.Windows.Forms.TextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.radMale = new System.Windows.Forms.RadioButton();
this.radFemale = new System.Windows.Forms.RadioButton();
this.cmbIsMarried = new System.Windows.Forms.ComboBox();
this.txtAge = new System.Windows.Forms.TextBox();
this.txtSalary = new System.Windows.Forms.TextBox();
this.txtMB = new System.Windows.Forms.TextBox();
this.btnAdd = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.btnPre = new System.Windows.Forms.Button();
this.btnNext = new System.Windows.Forms.Button();
this.btnLast = new System.Windows.Forms.Button();
this.btnFirst = new System.Windows.Forms.Button();
this.btnDelete = new System.Windows.Forms.Button();
this.btnFind = new System.Windows.Forms.Button();
this.btnModify = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// lblName
//
this.lblName.AutoSize = true;
this.lblName.Location = new System.Drawing.Point(13, 26);
this.lblName.Name = "lblName";
this.lblName.Size = new System.Drawing.Size(35, 12);
this.lblName.TabIndex = 0;
this.lblName.Text = "Name:";
//
// lblGender
//
this.lblGender.AutoSize = true;
this.lblGender.Location = new System.Drawing.Point(13, 63);
this.lblGender.Name = "lblGender";
this.lblGender.Size = new System.Drawing.Size(47, 12);
this.lblGender.TabIndex = 1;
this.lblGender.Text = "Gender:";
//
// lblAge
//
this.lblAge.AutoSize = true;
this.lblAge.Location = new System.Drawing.Point(15, 134);
this.lblAge.Name = "lblAge";
this.lblAge.Size = new System.Drawing.Size(29, 12);
this.lblAge.TabIndex = 2;
this.lblAge.Text = "Age:";
//
// lblSalary
//
this.lblSalary.AutoSize = true;
this.lblSalary.Location = new System.Drawing.Point(12, 208);
this.lblSalary.Name = "lblSalary";
this.lblSalary.Size = new System.Drawing.Size(47, 12);
this.lblSalary.TabIndex = 3;
this.lblSalary.Text = "Salary:";
//
// lblMB
//
this.lblMB.AutoSize = true;
this.lblMB.Location = new System.Drawing.Point(13, 247);
this.lblMB.Name = "lblMB";
this.lblMB.Size = new System.Drawing.Size(77, 12);
this.lblMB.TabIndex = 4;
this.lblMB.Text = "Moble Phone:";
//
// lblIsMarried
//
this.lblIsMarried.AutoSize = true;
this.lblIsMarried.Location = new System.Drawing.Point(13, 169);
this.lblIsMarried.Name = "lblIsMarried";
this.lblIsMarried.Size = new System.Drawing.Size(71, 12);
this.lblIsMarried.TabIndex = 5;
this.lblIsMarried.Text = "Is Married:";
//
// txtName
//
this.txtName.Location = new System.Drawing.Point(117, 26);
this.txtName.Name = "txtName";
this.txtName.Size = new System.Drawing.Size(141, 21);
this.txtName.TabIndex = 6;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.radFemale);
this.groupBox1.Controls.Add(this.radMale);
this.groupBox1.Location = new System.Drawing.Point(117, 63);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(141, 48);
this.groupBox1.TabIndex = 7;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Selection Item";
//
// radMale
//
this.radMale.AutoSize = true;
this.radMale.Location = new System.Drawing.Point(6, 21);
this.radMale.Name = "radMale";
this.radMale.Size = new System.Drawing.Size(47, 16);
this.radMale.TabIndex = 0;
this.radMale.Text = "Male";
this.radMale.UseVisualStyleBackColor = true;
//
// radFemale
//
this.radFemale.AutoSize = true;
this.radFemale.Location = new System.Drawing.Point(70, 21);
this.radFemale.Name = "radFemale";
this.radFemale.Size = new System.Drawing.Size(59, 16);
this.radFemale.TabIndex = 1;
this.radFemale.TabStop = true;
this.radFemale.Text = "Female";
this.radFemale.UseVisualStyleBackColor = true;
//
// cmbIsMarried
//
this.cmbIsMarried.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbIsMarried.FormattingEnabled = true;
this.cmbIsMarried.Items.AddRange(new object[] {
"是",
"否"});
this.cmbIsMarried.Location = new System.Drawing.Point(117, 169);
this.cmbIsMarried.Name = "cmbIsMarried";
this.cmbIsMarried.Size = new System.Drawing.Size(141, 20);
this.cmbIsMarried.TabIndex = 8;
//
// txtAge
//
this.txtAge.Location = new System.Drawing.Point(117, 134);
this.txtAge.Name = "txtAge";
this.txtAge.Size = new System.Drawing.Size(141, 21);
this.txtAge.TabIndex = 9;
//
// txtSalary
//
this.txtSalary.Location = new System.Drawing.Point(117, 208);
this.txtSalary.Name = "txtSalary";
this.txtSalary.Size = new System.Drawing.Size(141, 21);
this.txtSalary.TabIndex = 10;
//
// txtMB
//
this.txtMB.Location = new System.Drawing.Point(117, 247);
this.txtMB.Name = "txtMB";
this.txtMB.Size = new System.Drawing.Size(141, 21);
this.txtMB.TabIndex = 11;
//
// btnAdd
//
this.btnAdd.Location = new System.Drawing.Point(37, 328);
this.btnAdd.Name = "btnAdd";
this.btnAdd.Size = new System.Drawing.Size(63, 23);
this.btnAdd.TabIndex = 12;
this.btnAdd.Text = "Add(&a)";
this.btnAdd.UseVisualStyleBackColor = true;
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(265, 368);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(52, 23);
this.btnCancel.TabIndex = 13;
this.btnCancel.Text = "Cancel(&c)";
this.btnCancel.UseVisualStyleBackColor = true;
//
// btnPre
//
this.btnPre.Location = new System.Drawing.Point(103, 290);
this.btnPre.Name = "btnPre";
this.btnPre.Size = new System.Drawing.Size(63, 23);
this.btnPre.TabIndex = 14;
this.btnPre.Text = "Pre(&p)";
this.btnPre.UseVisualStyleBackColor = true;
this.btnPre.Click += new System.EventHandler(this.btnPre_Click);
//
// btnNext
//
this.btnNext.Location = new System.Drawing.Point(168, 290);
this.btnNext.Name = "btnNext";
this.btnNext.Size = new System.Drawing.Size(63, 23);
this.btnNext.TabIndex = 15;
this.btnNext.Text = "Next(&n)";
this.btnNext.UseVisualStyleBackColor = true;
this.btnNext.Click += new System.EventHandler(this.btnNext_Click);
//
// btnLast
//
this.btnLast.Location = new System.Drawing.Point(235, 290);
this.btnLast.Name = "btnLast";
this.btnLast.Size = new System.Drawing.Size(63, 23);
this.btnLast.TabIndex = 16;
this.btnLast.Text = "Last(&l)";
this.btnLast.UseVisualStyleBackColor = true;
this.btnLast.Click += new System.EventHandler(this.btnLast_Click);
//
// btnFirst
//
this.btnFirst.Location = new System.Drawing.Point(37, 290);
this.btnFirst.Name = "btnFirst";
this.btnFirst.Size = new System.Drawing.Size(63, 23);
this.btnFirst.TabIndex = 17;
this.btnFirst.Text = "First(&f)";
this.btnFirst.UseVisualStyleBackColor = true;
this.btnFirst.Click += new System.EventHandler(this.btnFirst_Click);
//
// btnDelete
//
this.btnDelete.Location = new System.Drawing.Point(235, 328);
this.btnDelete.Name = "btnDelete";
this.btnDelete.Size = new System.Drawing.Size(63, 23);
this.btnDelete.TabIndex = 18;
this.btnDelete.Text = "Delete(&d)";
this.btnDelete.UseVisualStyleBackColor = true;
this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
//
// btnFind
//
this.btnFind.Location = new System.Drawing.Point(168, 328);
this.btnFind.Name = "btnFind";
this.btnFind.Size = new System.Drawing.Size(63, 23);
this.btnFind.TabIndex = 19;
this.btnFind.Text = "Find(&f)";
this.btnFind.UseVisualStyleBackColor = true;
this.btnFind.Click += new System.EventHandler(this.btnFind_Click);
//
// btnModify
//
this.btnModify.Location = new System.Drawing.Point(103, 328);
this.btnModify.Name = "btnModify";
this.btnModify.Size = new System.Drawing.Size(63, 23);
this.btnModify.TabIndex = 20;
this.btnModify.Text = "Modifily(&m)";
this.btnModify.UseVisualStyleBackColor = true;
this.btnModify.Click += new System.EventHandler(this.btnModify_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.btnCancel;
this.ClientSize = new System.Drawing.Size(319, 393);
this.Controls.Add(this.btnModify);
this.Controls.Add(this.btnFind);
this.Controls.Add(this.btnDelete);
this.Controls.Add(this.btnFirst);
this.Controls.Add(this.btnLast);
this.Controls.Add(this.btnNext);
this.Controls.Add(this.btnPre);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnAdd);
this.Controls.Add(this.txtMB);
this.Controls.Add(this.txtSalary);
this.Controls.Add(this.txtAge);
this.Controls.Add(this.cmbIsMarried);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.txtName);
this.Controls.Add(this.lblIsMarried);
this.Controls.Add(this.lblMB);
this.Controls.Add(this.lblSalary);
this.Controls.Add(this.lblAge);
this.Controls.Add(this.lblGender);
this.Controls.Add(this.lblName);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label lblName;
private System.Windows.Forms.Label lblGender;
private System.Windows.Forms.Label lblAge;
private System.Windows.Forms.Label lblSalary;
private System.Windows.Forms.Label lblMB;
private System.Windows.Forms.Label lblIsMarried;
private System.Windows.Forms.TextBox txtName;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.RadioButton radFemale;
private System.Windows.Forms.RadioButton radMale;
private System.Windows.Forms.ComboBox cmbIsMarried;
private System.Windows.Forms.TextBox txtAge;
private System.Windows.Forms.TextBox txtSalary;
private System.Windows.Forms.TextBox txtMB;
private System.Windows.Forms.Button btnAdd;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Button btnPre;
private System.Windows.Forms.Button btnNext;
private System.Windows.Forms.Button btnLast;
private System.Windows.Forms.Button btnFirst;
private System.Windows.Forms.Button btnDelete;
private System.Windows.Forms.Button btnFind;
private System.Windows.Forms.Button btnModify;
}
}
主界面的事件响应代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace EmployeeManagementSystem
{
/// <summary>
/// solution:
/// when delete or modify a employee ,read all the information of employee,and
/// store into a object array .then change the record ,then overwrite the dat file
/// </summary>
public partial class Form1 : Form
{
private int _pos;
public Form1()
{
InitializeComponent();
_pos = 0;
}
/// <summary>
/// add a record;
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAdd_Click(object sender, EventArgs e)
{
Employee objEmployee = new Employee();
BinaryOperator objBO = new BinaryOperator();
objEmployee.Name = txtName.Text.Trim();
objEmployee.Age = Convert .ToInt32 (txtAge.Text.Trim());
objEmployee.Salary =Convert .ToInt32 ( txtSalary.Text.Trim());
objEmployee.Mb = txtMB.Text.Trim();
if (radFemale.Checked)
{
objEmployee.Sex = Gender.Female;
}
else
{
objEmployee.Sex = Gender.Male;
}
switch (cmbIsMarried.SelectedIndex)
{
case 0:
{
objEmployee.Ismarried = true;
break;
}
case 1:
{
objEmployee.Ismarried = false;
break;
}
}
objBO.AddEmployee(objEmployee);
objBO.GetTotalEmployee();
try
{
Display(objBO.GetEmployee(objBO .Totalcounter ));
_pos = objBO.Totalcounter;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
ChangePosition();
}
/// <summary>
/// when the windows display ,initial it;
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_Load(object sender, EventArgs e)
{
BinaryOperator objBO = new BinaryOperator();
Employee objEmployee = new Employee();
objEmployee = objBO.GetEmployee(1);
if (objBO.Totalcounter == 1)
{
btnLast.Enabled = false;
btnNext.Enabled = false;
btnPre.Enabled = false;
btnFirst.Enabled = false;
}
if (objBO.Totalcounter == 0)
{
btnLast.Enabled = false;
btnNext.Enabled = false;
btnPre.Enabled = false;
btnFirst.Enabled = false;
btnModify.Enabled = false;
btnDelete.Enabled = false;
btnFind.Enabled = false;
}
if (objEmployee != null)
{
_pos = 1;
}
else
{
_pos = 0;
return;
}
Display(objEmployee );
}
/// <summary>
/// display a employee 's information on form;
/// </summary>
/// <param name="objEmp"></param>
private void Display(Employee objEmp)
{
txtName.Text = objEmp.Name;
txtAge.Text = objEmp.Age.ToString();
txtSalary.Text = objEmp.Salary.ToString();
txtMB.Text = objEmp.Mb;
if (objEmp.Ismarried)
{
cmbIsMarried.SelectedIndex = 0;
}
else
{
cmbIsMarried.SelectedIndex = 1;
}
if (objEmp.Sex == Gender.Female)
{
radFemale.Checked = true;
}
else
{
radMale.Checked = true;
}
}
/// <summary>
/// go to the first record
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnFirst_Click(object sender, EventArgs e)
{
BinaryOperator bo = new BinaryOperator();
_pos = 1;
ChangePosition();
if ((bo.GetEmployee(_pos)) != null)
{
Display(bo.GetEmployee(_pos));
}
else
{
MessageBox.Show("In this system ,there have not a employee!");
}
}
/// <summary>
/// go to the pre record
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnPre_Click(object sender, EventArgs e)
{
BinaryOperator bo = new BinaryOperator();
_pos -= 1;
ChangePosition();
if ((bo.GetEmployee(_pos)) != null)
{
Display(bo.GetEmployee(_pos));
}
else
{
MessageBox.Show("In this system ,there have not a employee!");
}
}
/// <summary>
/// go to the next record
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnNext_Click(object sender, EventArgs e)
{
BinaryOperator bo = new BinaryOperator();
_pos += 1;
ChangePosition();
if ((bo.GetEmployee(_pos)) != null)
{
Display(bo.GetEmployee(_pos));
}
else
{
MessageBox.Show("In this system ,there have not a employee!");
}
}
/// <summary>
/// go to the last record;
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnLast_Click(object sender, EventArgs e)
{
BinaryOperator objBO = new BinaryOperator();
_pos = objBO.Totalcounter;
ChangePosition();
if ((objBO.GetEmployee(_pos)) != null)
{
Display(objBO.GetEmployee(_pos));
}
else
{
MessageBox.Show("In this system ,there have not a employee!");
}
}
/// <summary>
/// modify a record
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnModify_Click(object sender, EventArgs e)
{
BinaryOperator objBO = new BinaryOperator();
Employee objTempEmp = new Employee();
try
{
objTempEmp.Name = txtName.Text.Trim();
objTempEmp.Age = Convert.ToInt32(txtAge.Text.Trim());
objTempEmp.Salary = Convert.ToInt32(txtSalary.Text.Trim());
objTempEmp.Mb = txtMB.Text.Trim();
}
catch(FormatException ex)
{
MessageBox.Show("Age,Salary,must a data ,not a string!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message );
}
if (radFemale.Checked)
{
objTempEmp.Sex = Gender.Female;
}
else
{
objTempEmp.Sex = Gender.Male;
}
switch (cmbIsMarried.SelectedIndex)
{
case 0:
{
objTempEmp.Ismarried = true;
break;
}
case 1:
{
objTempEmp.Ismarried = false ;
break;
}
default:
{
break;
}
}
objBO.Modify(_pos,objTempEmp );
try
{
Display(objBO.GetEmployee(_pos));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
/// <summary>
/// delete a record
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnDelete_Click(object sender, EventArgs e)
{
BinaryOperator objBO = new BinaryOperator();
if ((_pos == 1) && (objBO.Totalcounter == 1))
{
objBO.Delete(_pos);
ClearActiveX();
_pos = 0;
ChangePosition();
return;
}
objBO.Delete(_pos);
try
{
Display(objBO.GetEmployee(1));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message );
}
_pos = 1;
ChangePosition();
}
/// <summary>
/// when current position(_pos) changed ,use this method to change all the button 's
/// enable property
/// </summary>
private void ChangePosition()
{
BinaryOperator objBO = new BinaryOperator();
if ((_pos > 1) && (_pos < objBO.Totalcounter))
{
btnFirst.Enabled = true;
btnPre.Enabled = true;
btnNext.Enabled = true;
btnLast.Enabled = true;
}
if (_pos == 1)
{
btnFirst.Enabled = false ;
btnPre.Enabled = false;
if (objBO.Totalcounter > 1)
{
btnLast.Enabled = true;
btnNext.Enabled = true;
}
else
{
btnNext.Enabled = false ;
btnLast.Enabled = false ;
}
}
if (_pos == objBO.Totalcounter)
{
if (objBO.Totalcounter > 1)
{
btnFirst.Enabled = true;
btnPre.Enabled = true;
}
else
{
btnPre.Enabled = false;
btnFirst.Enabled = false ;
}
btnNext.Enabled = false ;
btnLast.Enabled = false ;
}
if (objBO.Totalcounter <= 0)
{
btnFirst.Enabled = false ;
btnPre.Enabled = false ;
btnNext.Enabled = false ;
btnLast.Enabled = false ;
}
if (objBO.Totalcounter > 0)
{
btnDelete.Enabled = true;
btnModify.Enabled = true;
btnFind.Enabled = true;
}
if (objBO.Totalcounter == 0)
{
btnDelete.Enabled = false ;
btnModify.Enabled = false ;
btnFind.Enabled = false ;
}
}
/// <summary>
/// when all the record is delete ,clear the from;
/// </summary>
private void ClearActiveX()
{
txtName.Text = "";
txtAge.Text = "";
txtSalary.Text = "";
txtMB.Text = "";
cmbIsMarried.SelectedIndex = -1;
radFemale.Checked = false;
radMale.Checked = false;
}
/// <summary>
/// find a employee by name;
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnFind_Click(object sender, EventArgs e)
{
frmFind objFind = new frmFind();
Employee objEmp = new Employee();
if (DialogResult.OK == objFind.ShowDialog())
{
try
{
BinaryOperator objTemp = new BinaryOperator();
objEmp = objTemp.Find(objFind.FindName);
if (objEmp != null)
{
Display(objEmp);
}
else
{
MessageBox.Show("People called " + objFind.FindName + " not founded");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
}
雇员类的代码
using System;
using System.Collections.Generic;
using System.Text;
namespace EmployeeManagementSystem
{
enum Gender {Male,Female}
class Employee
{
static private int _employeenumber;
public static int Employeenumber
{
get { return Employee._employeenumber; }
set { Employee._employeenumber = value; }
}
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
private Gender _sex;
internal Gender Sex
{
get { return _sex; }
set { _sex = value; }
}
private int _age;
public int Age
{
get { return _age; }
set { _age = value; }
}
private bool _ismarried;
public bool Ismarried
{
get { return _ismarried; }
set { _ismarried = value; }
}
private int _salary;
public int Salary
{
get { return _salary; }
set { _salary = value; }
}
private string _mb;
public string Mb
{
get { return _mb; }
set { _mb = value; }
}
public Employee()
{
_employeenumber = 0;
}
}
}
查找界面设计
namespace EmployeeManagementSystem
{
partial class frmFind
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnFind = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.txtFind = new System.Windows.Forms.TextBox();
this.lblName = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// btnFind
//
this.btnFind.Location = new System.Drawing.Point(124, 69);
this.btnFind.Name = "btnFind";
this.btnFind.Size = new System.Drawing.Size(75, 23);
this.btnFind.TabIndex = 0;
this.btnFind.Text = "Find(&f)";
this.btnFind.UseVisualStyleBackColor = true;
this.btnFind.Click += new System.EventHandler(this.btnFind_Click);
//
// btnCancel
//
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(205, 69);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 23);
this.btnCancel.TabIndex = 1;
this.btnCancel.Text = "Cancel(&c)";
this.btnCancel.UseVisualStyleBackColor = true;
//
// txtFind
//
this.txtFind.Location = new System.Drawing.Point(38, 28);
this.txtFind.Name = "txtFind";
this.txtFind.Size = new System.Drawing.Size(203, 21);
this.txtFind.TabIndex = 2;
//
// lblName
//
this.lblName.AutoSize = true;
this.lblName.Location = new System.Drawing.Point(13, 13);
this.lblName.Name = "lblName";
this.lblName.Size = new System.Drawing.Size(203, 12);
this.lblName.TabIndex = 3;
this.lblName.Text = "Please input the employee/'s name:";
//
// frmFind
//
this.AcceptButton = this.btnFind;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.btnCancel;
this.ClientSize = new System.Drawing.Size(286, 104);
this.Controls.Add(this.lblName);
this.Controls.Add(this.txtFind);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnFind);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "frmFind";
this.Text = "frmFind";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button btnFind;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.TextBox txtFind;
private System.Windows.Forms.Label lblName;
}
}
查找窗体处理程序
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace EmployeeManagementSystem
{
public partial class frmFind : Form
{
private string _findname;
public string FindName
{
get { return _findname; }
set { _findname = value; }
}
public frmFind()
{
InitializeComponent();
}
private void btnFind_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
this.FindName = txtFind.Text.Trim();
}
}
}
程序入口
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace EmployeeManagementSystem
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}