📄 phonebookform.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Sindasoft.GsmModem.PhoneBook;
namespace GsmModemDemo
{
/// <summary>
/// PhoneBookForm 的摘要说明。
/// </summary>
public class PhoneBookForm : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label indexLab;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label phoneLab;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label nameLab;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.ComboBox nameList;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.TextBox nameBox;
private System.Windows.Forms.TextBox phoneBox;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label booknameLab;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.Label countLab;
private System.Windows.Forms.Label maxcountLab;
private ModemPhoneBook phoneBook;
public PhoneBookForm(ModemPhoneBook phoneBook)
{
this.phoneBook = phoneBook;
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.nameList = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.panel1 = new System.Windows.Forms.Panel();
this.nameLab = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.phoneLab = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.indexLab = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.nameBox = new System.Windows.Forms.TextBox();
this.phoneBox = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.button6 = new System.Windows.Forms.Button();
this.label8 = new System.Windows.Forms.Label();
this.booknameLab = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.countLab = new System.Windows.Forms.Label();
this.label11 = new System.Windows.Forms.Label();
this.maxcountLab = new System.Windows.Forms.Label();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// nameList
//
this.nameList.Location = new System.Drawing.Point(112, 8);
this.nameList.Name = "nameList";
this.nameList.Size = new System.Drawing.Size(64, 20);
this.nameList.TabIndex = 0;
this.nameList.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 12);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 16);
this.label1.TabIndex = 1;
this.label1.Text = "当前电话本:";
//
// panel1
//
this.panel1.BackColor = System.Drawing.SystemColors.Info;
this.panel1.Controls.Add(this.nameLab);
this.panel1.Controls.Add(this.label5);
this.panel1.Controls.Add(this.phoneLab);
this.panel1.Controls.Add(this.label4);
this.panel1.Controls.Add(this.indexLab);
this.panel1.Controls.Add(this.label3);
this.panel1.Location = new System.Drawing.Point(32, 80);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(384, 80);
this.panel1.TabIndex = 2;
//
// nameLab
//
this.nameLab.BackColor = System.Drawing.SystemColors.ControlLight;
this.nameLab.Location = new System.Drawing.Point(64, 56);
this.nameLab.Name = "nameLab";
this.nameLab.Size = new System.Drawing.Size(168, 16);
this.nameLab.TabIndex = 5;
this.nameLab.Text = "label6";
//
// label5
//
this.label5.Location = new System.Drawing.Point(16, 56);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(56, 16);
this.label5.TabIndex = 4;
this.label5.Text = "姓名:";
//
// phoneLab
//
this.phoneLab.BackColor = System.Drawing.SystemColors.ControlLight;
this.phoneLab.Location = new System.Drawing.Point(64, 32);
this.phoneLab.Name = "phoneLab";
this.phoneLab.Size = new System.Drawing.Size(168, 16);
this.phoneLab.TabIndex = 3;
this.phoneLab.Text = "label5";
//
// label4
//
this.label4.Location = new System.Drawing.Point(16, 32);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(56, 16);
this.label4.TabIndex = 2;
this.label4.Text = "号码:";
//
// indexLab
//
this.indexLab.BackColor = System.Drawing.SystemColors.ControlLight;
this.indexLab.Location = new System.Drawing.Point(64, 8);
this.indexLab.Name = "indexLab";
this.indexLab.Size = new System.Drawing.Size(168, 16);
this.indexLab.TabIndex = 1;
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 8);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(64, 16);
this.label3.TabIndex = 0;
this.label3.Text = "索引号";
//
// label2
//
this.label2.Location = new System.Drawing.Point(32, 64);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(120, 16);
this.label2.TabIndex = 3;
this.label2.Text = "电话本当前项信息";
//
// button1
//
this.button1.Location = new System.Drawing.Point(40, 168);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(56, 23);
this.button1.TabIndex = 4;
this.button1.Text = "第一项";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(104, 168);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(56, 23);
this.button2.TabIndex = 5;
this.button2.Text = "最末项";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(168, 168);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(56, 23);
this.button3.TabIndex = 6;
this.button3.Text = "下一项";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(232, 168);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(56, 23);
this.button4.TabIndex = 7;
this.button4.Text = "前一项";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button5
//
this.button5.Location = new System.Drawing.Point(296, 168);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(56, 23);
this.button5.TabIndex = 8;
this.button5.Text = "删除";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// nameBox
//
this.nameBox.Location = new System.Drawing.Point(32, 240);
this.nameBox.Name = "nameBox";
this.nameBox.Size = new System.Drawing.Size(144, 21);
this.nameBox.TabIndex = 9;
this.nameBox.Text = "";
//
// phoneBox
//
this.phoneBox.Location = new System.Drawing.Point(200, 240);
this.phoneBox.Name = "phoneBox";
this.phoneBox.Size = new System.Drawing.Size(144, 21);
this.phoneBox.TabIndex = 10;
this.phoneBox.Text = "";
//
// label6
//
this.label6.Location = new System.Drawing.Point(32, 224);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(100, 16);
this.label6.TabIndex = 11;
this.label6.Text = "姓名:";
//
// label7
//
this.label7.Location = new System.Drawing.Point(200, 224);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(100, 16);
this.label7.TabIndex = 12;
this.label7.Text = "电话号码:";
//
// button6
//
this.button6.Location = new System.Drawing.Point(32, 272);
this.button6.Name = "button6";
this.button6.TabIndex = 13;
this.button6.Text = "添加记录";
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// label8
//
this.label8.Location = new System.Drawing.Point(208, 8);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(80, 16);
this.label8.TabIndex = 14;
this.label8.Text = "电话本名称:";
//
// booknameLab
//
this.booknameLab.Location = new System.Drawing.Point(280, 8);
this.booknameLab.Name = "booknameLab";
this.booknameLab.Size = new System.Drawing.Size(152, 24);
this.booknameLab.TabIndex = 15;
this.booknameLab.Text = "label9";
//
// label9
//
this.label9.Location = new System.Drawing.Point(32, 40);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(56, 16);
this.label9.TabIndex = 16;
this.label9.Text = "记录数:";
//
// countLab
//
this.countLab.Location = new System.Drawing.Point(88, 40);
this.countLab.Name = "countLab";
this.countLab.Size = new System.Drawing.Size(112, 16);
this.countLab.TabIndex = 17;
//
// label11
//
this.label11.Location = new System.Drawing.Point(208, 40);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(80, 16);
this.label11.TabIndex = 18;
this.label11.Text = "最大记录数:";
//
// maxcountLab
//
this.maxcountLab.Location = new System.Drawing.Point(280, 40);
this.maxcountLab.Name = "maxcountLab";
this.maxcountLab.Size = new System.Drawing.Size(120, 16);
this.maxcountLab.TabIndex = 19;
//
// PhoneBookForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(440, 341);
this.Controls.Add(this.maxcountLab);
this.Controls.Add(this.label11);
this.Controls.Add(this.countLab);
this.Controls.Add(this.label9);
this.Controls.Add(this.booknameLab);
this.Controls.Add(this.label8);
this.Controls.Add(this.button6);
this.Controls.Add(this.label7);
this.Controls.Add(this.label6);
this.Controls.Add(this.phoneBox);
this.Controls.Add(this.nameBox);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.label2);
this.Controls.Add(this.panel1);
this.Controls.Add(this.label1);
this.Controls.Add(this.nameList);
this.Name = "PhoneBookForm";
this.ShowInTaskbar = false;
this.Text = "电话本管理";
this.Load += new System.EventHandler(this.PhoneBookForm_Load);
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
int i = this.nameList.SelectedIndex;
string s = this.nameList.Items[i].ToString();
this.phoneBook[s].SetToCurrent();
this.SetPhoneBookInfo();
this.ShowPhoneBookItem(this.phoneBook.Current);
}
private void SetPhoneBookInfo()
{
this.booknameLab.Text = this.phoneBook.PhoneBookName;
this.countLab.Text = this.phoneBook.Count.ToString();
this.maxcountLab.Text = this.phoneBook.MaxCount.ToString();
}
private void PhoneBookForm_Load(object sender, System.EventArgs e)
{
foreach (string s in this.phoneBook.StorageNames)
{
this.nameList.Items.Add(s);
}
this.nameList.SelectedIndex = 0;
PhoneBookItem pbi = phoneBook.Current;
this.ShowPhoneBookItem(pbi);
}
private void ShowPhoneBookItem(PhoneBookItem pbi)
{
if (pbi != null)
{
this.phoneLab.Text = pbi.PhoneNumber;
this.nameLab.Text = pbi.Name;
this.indexLab.Text = pbi.IndexNo.ToString();
}
}
private void button1_Click(object sender, System.EventArgs e)
{
this.ShowPhoneBookItem(this.phoneBook.FirstItem);
}
private void button2_Click(object sender, System.EventArgs e)
{
this.ShowPhoneBookItem(this.phoneBook.LastItem);
}
private void button3_Click(object sender, System.EventArgs e)
{
this.ShowPhoneBookItem(this.phoneBook.Next);
}
private void button4_Click(object sender, System.EventArgs e)
{
this.ShowPhoneBookItem(this.phoneBook.Previous);
}
private void button6_Click(object sender, System.EventArgs e)
{
this.phoneBook.Add(this.phoneBox.Text,this.nameBox.Text);
this.SetPhoneBookInfo();
}
private void button5_Click(object sender, System.EventArgs e)
{
this.phoneBook.Remove();
this.SetPhoneBookInfo();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -