Hi everyone I studying about programming on windows mobile. And I build a mini program about "manage contacts" with functions: Add, Edit, Delete, Search and Sort by group. But I don't know how to complete function : search and BackUp/recovery contacts! Can you help me?
Description about Search function: I create a textbox and listBox, when i press any word on textbox, Name of contacts containing word will display on listbox! Can you help me?
This is my demo, I convert and repair from example of windows mobile 5.0
This is form main, and picture about main form here : http://3.bp.blogspot.com/-lMmKCF6-REQ/TcqwNk9kgdI/AAAAAAAAAB4/-Eis3miMHy0/s320/Main.JPG
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using Microsoft.WindowsMobile.PocketOutlook;
using Microsoft.WindowsMobile.Telephony;
namespace ManagerContacts
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class ContactSelector : System.Windows.Forms.Form
{
private System.Windows.Forms.ListBox listBox1;
private OutlookSession outlookSession;
private System.Windows.Forms.TextBox smsText;
//private System.Windows.Forms.Button btnCallWork;
private System.Windows.Forms.Button btnEdit;
private System.Windows.Forms.Button btnNew;
private System.Windows.Forms.Button btnSendSms;
private Button bntDel;
private TextBox textBox1;
private PictureBox pictureBox1;
private Button button2;
private Button bntBackUp;
private PictureBox pictureBox;
private Contact contactToSelect;
//
// Constructor
//
public ContactSelector()
{
this.outlookSession = new OutlookSession();
this.InitializeComponent();
this.InitializeListBox();
}
/// <summary>
/// This function displays a dialog that lets the user pick a contact from a List or
/// create a new contact.
/// </summary>
/// <returns>The function returns the Contact chosen or a new Contact object if the user pressed "New" on the dialog.</returns>
public Contact Select()
{
this.ShowDialog();
return this.contactToSelect;
}
// Clean up any resources being used.
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ContactSelector));
this.btnEdit = new System.Windows.Forms.Button();
this.listBox1 = new System.Windows.Forms.ListBox();
this.btnNew = new System.Windows.Forms.Button();
this.btnSendSms = new System.Windows.Forms.Button();
this.smsText = new System.Windows.Forms.TextBox();
this.bntDel = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.button2 = new System.Windows.Forms.Button();
this.bntBackUp = new System.Windows.Forms.Button();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
//
// btnEdit
//
this.btnEdit.Location = new System.Drawing.Point(152, 70);
this.btnEdit.Name = "btnEdit";
this.btnEdit.Size = new System.Drawing.Size(79, 24);
this.btnEdit.TabIndex = 7;
this.btnEdit.Text = "Edit Contact";
this.btnEdit.Click += new System.EventHandler(this.EditButton_Click);
//
// listBox1
//
this.listBox1.Location = new System.Drawing.Point(10, 32);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(136, 198);
this.listBox1.TabIndex = 6;
//
// btnNew
//
this.btnNew.Location = new System.Drawing.Point(152, 40);
this.btnNew.Name = "btnNew";
this.btnNew.Size = new System.Drawing.Size(79, 24);
this.btnNew.TabIndex = 5;
this.btnNew.Text = "Add Contact";
this.btnNew.Click += new System.EventHandler(this.NewButton_Click);
//
// btnSendSms
//
this.btnSendSms.Location = new System.Drawing.Point(201, 240);
this.btnSendSms.Name = "btnSendSms";
this.btnSendSms.Size = new System.Drawing.Size(36, 24);
this.btnSendSms.TabIndex = 4;
this.btnSendSms.Text = "SMS";
this.btnSendSms.Click += new System.EventHandler(this.SendSmsButton_Click);
//
// smsText
//
this.smsText.Location = new System.Drawing.Point(10, 240);
this.smsText.Name = "smsText";
this.smsText.Size = new System.Drawing.Size(188, 21);
this.smsText.TabIndex = 3;
this.smsText.Text = "Write SMS Text here.";
//
// bntDel
//
this.bntDel.Location = new System.Drawing.Point(152, 100);
this.bntDel.Name = "bntDel";
this.bntDel.Size = new System.Drawing.Size(79, 24);
this.bntDel.TabIndex = 8;
this.bntDel.Text = "Del Contact";
this.bntDel.Click += new System.EventHandler(this.bntDel_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(43, 5);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(188, 21);
this.textBox1.TabIndex = 9;
this.textBox1.Text = "Search";
//
// pictureBox1
//
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(10, 5);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(24, 24);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
//
// button2
//
this.button2.Location = new System.Drawing.Point(158, 267);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(79, 24);
this.button2.TabIndex = 13;
this.button2.Text = "Exit";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// bntBackUp
//
this.bntBackUp.Location = new System.Drawing.Point(10, 266);
this.bntBackUp.Name = "bntBackUp";
this.bntBackUp.Size = new System.Drawing.Size(142, 27);
this.bntBackUp.TabIndex = 15;
this.bntBackUp.Text = "BackUp And Recovery";
this.bntBackUp.Click += new System.EventHandler(this.bntBackUp_Click);
//
// pictureBox
//
this.pictureBox.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox.Image")));
this.pictureBox.Location = new System.Drawing.Point(152, 130);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(85, 83);
this.pictureBox.Click += new System.EventHandler(this.pictureBox_Click);
//
// ContactSelector
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
this.ClientSize = new System.Drawing.Size(240, 296);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.bntBackUp);
this.Controls.Add(this.button2);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.bntDel);
this.Controls.Add(this.smsText);
this.Controls.Add(this.btnSendSms);
this.Controls.Add(this.btnNew);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.btnEdit);
this.KeyPreview = true;
this.Name = "ContactSelector";
this.Text = "Co开发者_运维知识库ntact Selector";
this.ResumeLayout(false);
}
private void InitializeListBox()
{
this.listBox1.DataSource = null;
this.listBox1.DataSource = this.outlookSession.Contacts.Items;
this.listBox1.DisplayMember = "FileAs";
this.listBox1.ValueMember = "ItemId";
}
#endregion
static void Main()
{
Application.Run(new ContactSelector());
}
private void NewButton_Click(object sender, System.EventArgs e)
{
// Add contact to the contacts folder.
// Just do an update once the information has been entered.
contactToSelect = new Contact();
this.outlookSession.Contacts.Items.Add(contactToSelect);
// Edit the newly created contact.
ContactEditor contactDialog = new ContactEditor();
contactDialog.Edit(ref contactToSelect);
this.InitializeListBox();
}
private void EditButton_Click(object sender, System.EventArgs e)
{
if (this.listBox1.SelectedItem != null)
{
contactToSelect = (Contact)this.listBox1.SelectedItem;
}
ContactEditor contactDialog = new ContactEditor();
contactDialog.Edit(ref contactToSelect);
}
private void SendSmsButton_Click(object sender, System.EventArgs e)
{
try
{
contactToSelect = (Contact)this.listBox1.SelectedItem;
if (outlookSession.SmsAccount == null)
throw new ArgumentException("The account is not initialized");
MessageBox.Show("Transport:"+outlookSession.SmsAccount.Name);
SmsMessage s = new SmsMessage(contactToSelect.MobileTelephoneNumber, this.smsText.Text);
s.Body = this.smsText.Text; //Create some input.
s.Send();
}
catch (NullReferenceException except)
{
MessageBox.Show(except.ToString());
}
}
private void bntDel_Click(object sender, EventArgs e)
{
contactToSelect = (Contact)this.listBox1.SelectedItem;
contactToSelect.Delete();
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void bntBackUp_Click(object sender, EventArgs e)
{
MainForm BR = new MainForm();
BR.Show();
}
private void pictureBox_Click(object sender, EventArgs e)
{
/*
* contactToSelect = (Contact)this.listBox1.SelectedItem;
Phone p = new Phone();
p.Talk(contactToSelect.MobileTelephoneNumber);
*/
}
}
}
Thank you very much!
Your statement is very broad, and I agree with IAbstract, I will not download your .rar file.
You may be able to search by having the user enter their query into a textbox and click a button. Then it will compare the textbox string with a dictionary that is created on the application load. This dictionary will contain the name and then data that will let you navigate to the selected contact.
private void button_Click(object sender, EventArgs e)
{
if (myDict.ContainsKey(textBox1.Text))
{
string contact = myDict[textBox1.Text]; //I dont know how you would store
//the navigation info. Here it is a string
//
//Navigate to relevant contact
//
}
else
{
//
//return that no contacts were found
//
}
I didn't compile this code, so If somebody sees that I got something wrong, just comment and I will fix.
精彩评论