C#在Winform程式中顯示QQ線上狀態

來源:互聯網
上載者:User

首先,引入必要的命名空間

using System.Windows.Forms;  using System.Net;

其次,在Form中拖入一個PictureBox控制項,並設定其SizeMode為AutoSize。同時拖入一個Timer控制項。

然後在表單建構函式中寫入代碼

timer1.Tag = 0;timer1.Interval = 10;timer1.Enabled = true;

然後在Timer的Tick事件中寫入代碼

Timer timer = (Timer)sender; if (timer.Tag != null){    if ((int)timer.Tag == 0)    {        timer.Enabled = false;        timer.Tag = 1;        try         {            Image img = Image.FromStream(WebRequest.Create(qqgif).GetResponse().GetResponseStream());            pictureBox1.Image = img;        }        catch         {            pictureBox1.Image = Properties.Resources.pa;        }        timer.Interval = 1000 * 10;        timer.Enabled = true;    }     else     {        try         {            Image img = Image.FromStream(WebRequest.Create(qqgif).GetResponse().GetResponseStream());            pictureBox1.Image = img;        }        catch         {            pictureBox1.Image = Properties.Resources.pa;        }    }}

最後,在PictureBox的Click事件中寫入代碼

 

System.Diagnostics.Process.Start("iexplore.exe", qqmsg);

以上代碼中 qqgif和qqmsg 的定義

 

private const string qqgif = "http://wpa.qq.com/pa?p=2:303071318:50"; private const string qqmsg = "tencent://message/?uin=303071318";



PS:如上過程,在擷取QQ線上表徵圖時會有點卡的感覺,可以修改成多線程方式來解決。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.