📄 usercontrol1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsMobile.PocketOutlook;
using System.Collections;
namespace winceSms
{
public partial class UserControl1 : UserControl
{
// public override sealed event ListChangedEventHandler ListChanged;
ContactCollection contacts;
private ArrayList phones = new ArrayList();
public UserControl1()
{
components = null;
phones = new ArrayList();
InitializeComponent();
OutlookSession session = new OutlookSession();
contacts = session.Contacts.Items;
treeView1.Nodes.Clear();
contacts.Sort("LastName", false);
TreeNode node = null;
for (int i = 0; i < this.contacts.Count; i++)
{
TreeNode contactPhone = this.GetContactPhone(this.contacts.AddNew());
if ((i % 15) == 0)
{
node = new TreeNode(this.contacts.AddNew().LastName + this.contacts.AddNew().FirstName);
this.treeView1.Nodes.Add(node);
}
if ((contactPhone != null) & (node != null))
{
node.Nodes.Add(contactPhone);
}
}
// ListChanged=new ListChangedEventHandler(contactchanged);
// contacts.ListChanged+= ListChanged;
// contacts.SupportsChangeNotification = true;
}
public TreeNode GetContactPhone(Contact c)
{
ArrayList list = new ArrayList();
TreeNode node = new TreeNode(c.LastName + c.LastName);
if (c.Business2TelephoneNumber != "")
{
list.Add(c.Business2TelephoneNumber);
}
if (c.BusinessTelephoneNumber != "")
{
list.Add(c.BusinessTelephoneNumber);
}
if (c.MobileTelephoneNumber != "")
{
list.Add(c.MobileTelephoneNumber);
}
if (c.Home2TelephoneNumber != "")
{
list.Add(c.Home2TelephoneNumber);
}
if (c.HomeTelephoneNumber != "")
{
list.Add(c.HomeTelephoneNumber);
}
if (c.RadioTelephoneNumber != "")
{
list.Add(c.RadioTelephoneNumber);
}
if (list.Count == 0)
{
node = null;
}
if (list.Count == 1)
{
node.Tag = list[0];
node.Text = string.Format("{0} 电话:{1}", node.Text, list[0]);
return node;
}
TreeNode[] nodeArray = new TreeNode[list.Count];
for (int i = 0; i < list.Count; i++)
{
nodeArray[i] = new TreeNode(list[i].ToString());
nodeArray[i].Tag = list[i].ToString();
node.Nodes.Add(nodeArray[i]).ToString();
}
return node;
}
private void setphones()
{
if (treeView1.SelectedNode != null & treeView1.SelectedNode.Tag != null)
{
treeView1.SelectedNode.Checked = !treeView1.SelectedNode.Checked;
// treeView1.SelectedNode.Toggle();
string nowphone = treeView1.SelectedNode.Tag.ToString();
if (treeView1.SelectedNode.Checked)
{
phones.Add(nowphone);
treeView1.SelectedNode.ImageIndex = 2;
treeView1.SelectedNode.SelectedImageIndex = 2;
}
else
{
phones.Remove(nowphone);
treeView1.SelectedNode.ImageIndex = 0;
treeView1.SelectedNode.SelectedImageIndex = 0;
}
treeView1.Refresh();
}
}
public string GetPones()
{
if (phones.Count == 0)
{
MessageBox.Show("没有选中项");
return "";
}
else
{
return string.Join(",", (string[])phones.ToArray("".GetType()));
}
}
private void treeView1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\r')
{
this.setphones();
}
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
try
{
bool checkBoxes = this.treeView1.CheckBoxes;
this.setphones();
}
catch (Exception)
{
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -