zoukankan      html  css  js  c++  java
  • C#在Winform程序中显示QQ在线状态

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

    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在线图标时会有点卡的感觉,可以修改成多线程方式来解决。
  • 相关阅读:
    cxVerticalGrid赋值是实时更新
    cxGrid类似pagecontrol的效果
    cxgrid属性说明,每次用的时候费时费力查找。
    做一个平均数,合计数的sql查询
    FDMemTable 提示操作速度尤其是循环
    手机号码验证
    取字符串长度
    DELPHI 获取本月 的第一天 和 最后一天
    SQL Server 断开某个数据库所有连接(还原的时候需要)转自用保留
    元宇宙六大核心技术
  • 原文地址:https://www.cnblogs.com/luoshupeng/p/2938407.html
Copyright © 2011-2022 走看看