csharp skype send message in winform

  1 using System;
  2 using System.Collections.Generic;
  3 using System.ComponentModel;
  4 using System.Data;
  5 using System.Drawing;
  6 using System.Linq;
  7 using System.Text;
  8 using System.Windows.Forms;
  9 using SKYPE4COMLib;
 10 using System.Collections;
 11 
 12 namespace Skype
 13 {
 14     /// <summary>
 15     /// 20120804 塗聚文
 16     /// 締友計算機信息技術有限公司
 17     /// Geovin Du geovindu@163.com
 18     /// </summary>
 19     public partial class Form1 : Form
 20     {
 21         string strskypeuser = string.Empty;
 22         string strskypeid = string.Empty;
 23         SKYPE4COMLib.Skype oSkype = new SKYPE4COMLib.Skype();
 24         /// <summary>
 25         ///
 26         /// </summary>
 27         public Form1()
 28         {
 29             InitializeComponent();
 30         }
 31 
 32         
 33 
 34 
 35         /// <summary>
 36         ///
 37         /// </summary>
 38         /// <param name="sender"></param>
 39         /// <param name="e"></param>
 40         private void button1_Click(object sender, EventArgs e)
 41         {
 42             //不能發送文件在WEB上可以用
 43             //string file = @"E:\金蝶KIS系列产品简介.xls";
 44             //oSkype.Client.OpenFileTransferDialog(strskypeid, file);//打開發送文件
 45             oSkype.SendMessage(strskypeid, strskypeuser + ":" + textBox1.Text);
 46 
 47 
 48         }
 49         /// <summary>
 50         ///
 51         /// </summary>
 52         /// <param name="sender"></param>
 53         /// <param name="e"></param>
 54         private void Form1_Load(object sender, EventArgs e)
 55         {
 56 
 57 
 58             if (oSkype.Client.IsRunning == false)//判断客户端是否运行
 59             {
 60                 //是否能免費提供登錄調用的API?不管是DESKTOP或是WEB
 61                 oSkype.Client.Start(true, true);//運行
 62                 MessageBox.Show("請登錄SKPYE再重新操作", "請注意");
 63                 return;
 64 
 65             }
 66             else
 67             {
 68                 this.listBox1.DataSource = skyuselist();
 69                 this.listBox1.DisplayMember = "userDisplayName";
 70                 this.listBox1.ValueMember = "userLoginName";
 71             }
 72                 ////初始化物件,預設會抓本機的Skype帳號資訊
 73                 //SKYPE4COMLib.Skype oSkype = new SKYPE4COMLib.Skype();
 74                 //UserCollection tFriends = oSkype.Friends;
 75 
 76                 ////取出所有的朋友資訊
 77                 //foreach (User tUser in oSkype.Friends)
 78                 //{
 79                 //    if (tUser.FullName.Trim() != "")
 80                 //    {
 81                 //        ListItem newItem = new ListItem(tUser.Handle, tUser.FullName);
 82                 //        listBox1.Items.Add(newItem);
 83                 //        this.listBox1.DisplayMember = "Name";
 84                 //        this.listBox1.ValueMember = "ID";
 85                 //        //listBox1.Items.Add(tUser.Handle);//賬號 //tUser.FullName //昵稱
 86                 //        //listBox1.Items.AddRange(tUser.FullName);
 87                 //    }
 88                         
 89                 //}
 90         }
 91 
 92         /// <summary>
 93         ///
 94         /// </summary>
 95         /// <returns></returns>
 96         private DataTable skyuselist()
 97         {
 98             DataTable d = new DataTable();
 99             //初始化物件,預設會抓本機的Skype帳號資訊
100             //SKYPE4COMLib.Skype oSkype = new SKYPE4COMLib.Skype();
101             UserCollection tFriends = oSkype.Friends;
102             d.Columns.Add("userLoginName", typeof(string));
103             d.Columns.Add("userDisplayName", typeof(string));
104             //取出所有的朋友資訊
105             foreach (User tUser in oSkype.Friends)
106             {
107                 if (tUser.FullName.Trim() != "")
108                 {
109                     //ListItem newItem = new ListItem(tUser.Handle, tUser.FullName);
110                     //listBox1.Items.Add(newItem);
111                     //this.listBox1.DisplayMember = "Name";
112                     //this.listBox1.ValueMember = "ID";
113                     //listBox1.Items.Add(tUser.Handle);//賬號 //tUser.FullName //昵稱
114                     //listBox1.Items.AddRange(tUser.FullName);
115                     d.Rows.Add(tUser.Handle, tUser.FullName);
116                 }
117                 else
118                 {
119                     d.Rows.Add(tUser.Handle, tUser.Handle);
120                 }
121                 
122             }
123             d.Rows.Add("geovindu", "geovindu");
124             return d;
125         }
126         /// <summary>
127         /// 選擇SKYPE用戶
128         /// </summary>
129         /// <param name="sender"></param>
130         /// <param name="e"></param>
131         private void listBox1_Click(object sender, EventArgs e)
132         {
133             strskypeuser= this.listBox1.Text;
134             strskypeid = this.listBox1.SelectedValue.ToString();
135             MessageBox.Show(strskypeuser+","+strskypeid);
136         }

 

posted @ 2012-08-03 11:25  ®Geovin Du Dream Park™  阅读(718)  评论(0编辑  收藏  举报