MainForm.cs
上传用户:linger1010
上传日期:2008-12-08
资源大小:561k
文件大小:3k
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using Microsoft.WindowsMobile.Telephony;
- namespace PlayingAPhoneCall
- {
- public partial class MainForm : Form
- {
- // 用于构造电话号码
- StringBuilder m_sbNumber = new StringBuilder(16);
- // 记录是否需要清空号码
- // 如果需要清空,则按下某一数字键后,原号码被清空,
- // 而按下的数字成为新号码的第一位
- // 例如,当拨过一次电话后,就需要清空
- bool m_needClear = false;
- public MainForm()
- {
- InitializeComponent();
- }
- /// <summary>
- /// 清空显示的电话号码。
- /// </summary>
- private void m_clearNumber()
- {
- m_sbNumber.Remove(0, m_sbNumber.Length);
- }
- /// <summary>
- /// 将缓存中的电话号码显示在屏幕上。
- /// </summary>
- private void m_refreshNumber()
- {
- m_lblNumber.Text = m_sbNumber.ToString();
- }
- /// <summary>
- /// 向号码中追加一个数字。
- /// </summary>
- /// <param name="num">要追加的数字。</param>
- private void m_appendNumber(char num)
- {
- if (m_needClear)
- m_clearNumber();
- m_sbNumber.Append(num);
- m_refreshNumber();
- m_needClear = false;
- }
- private void m_btnNum1_Click(object sender, EventArgs e)
- {
- m_appendNumber('1');
- }
- private void m_btnNum2_Click(object sender, EventArgs e)
- {
- m_appendNumber('2');
- }
- private void m_btnNum3_Click(object sender, EventArgs e)
- {
- m_appendNumber('3');
- }
- private void m_btnNum4_Click(object sender, EventArgs e)
- {
- m_appendNumber('4');
- }
- private void m_btnNum5_Click(object sender, EventArgs e)
- {
- m_appendNumber('5');
- }
- private void m_btnNum6_Click(object sender, EventArgs e)
- {
- m_appendNumber('6');
- }
- private void m_btnNum7_Click(object sender, EventArgs e)
- {
- m_appendNumber('7');
- }
- private void m_btnNum8_Click(object sender, EventArgs e)
- {
- m_appendNumber('8');
- }
- private void m_btnNum9_Click(object sender, EventArgs e)
- {
- m_appendNumber('9');
- }
- private void m_btnStar_Click(object sender, EventArgs e)
- {
- m_appendNumber('*');
- }
- private void m_btnNum0_Click(object sender, EventArgs e)
- {
- m_appendNumber('0');
- }
- private void m_btnSharp_Click(object sender, EventArgs e)
- {
- m_appendNumber('#');
- }
- private void m_btnBackspace_Click(object sender, EventArgs e)
- {
- if(m_sbNumber.Length > 0)
- m_sbNumber.Remove(m_sbNumber.Length - 1, 1);
- m_refreshNumber();
- }
- private void m_btnClear_Click(object sender, EventArgs e)
- {
- m_clearNumber();
- m_refreshNumber();
- }
- private void m_btnCall_Click(object sender, EventArgs e)
- {
- Phone p = new Phone();
- try
- {
- p.Talk(m_lblNumber.Text);
- }
- catch(Exception ex)
- {
- MessageBox.Show(
- String.Format("Error: {0}", ex.Message),
- "Talk",
- MessageBoxButtons.OK,
- MessageBoxIcon.Hand,
- MessageBoxDefaultButton.Button1);
- }
- }
- }
- }