您的位置:程序门 -> .net技术 -> c#



托盘程序闪动图标问题!


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


托盘程序闪动图标问题![已结贴,结贴人:winsmallcat]
发表于:2007-06-05 16:26:27 楼主
我想做的是一个新闻提醒小程序,如果有新的新闻托盘图标就闪动!为什么第一次闪动正常第二就不正常了闪动图标非常快,第三次有正常闪了!不知道为什么!希望高手帮我看下代码!或提供一些这方面的例子!using   system;
using   system.io;
using   system.net;
using   system.componentmodel;
using   system.data;
using   system.drawing;
using   system.text;
using   system.collections.generic;
using   system.windows.forms;


namespace   windowsapplication1
{
        public   partial   class   form1   :   form
        {
                private   bool   m_bflag   =   true;                
                //根据url地址得到网页的html源码
                private   string   getwebcontent(string   url)
                {
                        string   strresult   =   " ";
                        try
                        {
                                httpwebrequest   request   =   (httpwebrequest)webrequest.create(url);
                                //声明一个httpwebrequest请求
                                request.timeout   =   30000;
                                //设置连接超时时间
                                request.headers.set( "pragma ",   "no-cache ");
                                httpwebresponse   response   =   (httpwebresponse)request.getresponse();
                                stream   streamreceive   =   response.getresponsestream();
                                encoding   encoding   =   encoding.getencoding( "gb2312 ");
                                streamreader   streamreader   =   new   streamreader(streamreceive,   encoding);
                                strresult   =   streamreader.readtoend();
                                streamreader.close();
                        }
                        catch
                        {
                                messagebox.show( "出错 ");
                        }
                        return   strresult;
                }
               
                public   form1()
                {
                        initializecomponent();
                        this.notifyicon1.icon   =   new   icon( "1.ico ");
                        this.sizechanged   +=   new   system.eventhandler(this.form1_sizechanged);
                        this.timer2.enabled   =   true;
                        this.timer2.tick   +=   new   system.eventhandler(this.timer2_tick);
                }
                private   void   form1_sizechanged(object   sender,   system.eventargs   e)
                {
                        if   (this.windowstate   ==   formwindowstate.minimized)
                        {
                                this.hide();
                        }
                }

                //关闭
                private   void   toolstripmenuitem4_click(object   sender,   system.eventargs   e)
                {
                        this.close();
                }
                //显示
                private   void   toolstripmenuitem3_click(object   sender,   eventargs   e)
                {
                        if   (this.windowstate   ==   formwindowstate.minimized)
                        {
                                this.show();
                                this.windowstate   =   formwindowstate.normal;
                                this.activate();
                                this.timer1.stop();
                                this.notifyicon1.icon   =   new   icon( "1.ico ");
                        }
                }

                //抓
                private   void   timer2_tick(object   sender,   system.eventargs   e)
                {
                        //抓取数据
                        string   url   =   "http://192.168.2.27:91/admin/admin_user.asp ";
                        string   strwebcontent   =   getwebcontent(url);
                        filestream   fs   =   new   filestream(@ "1.txt ",   filemode.open,   fileaccess.read);
                        streamreader   sr   =   new   streamreader(fs);
                        string   strdata   =   sr.readtoend();
                        sr.close();
                        fs.close();
                        if   (strwebcontent   !=   strdata)
                        {
                                this.webbrowser1.refresh();
                                this.timer1.start();
                                this.timer1.tick   +=   new   eventhandler(this.timer1_tick);
                                streamwriter   sw   =   new   streamwriter( "1.txt ");
                                sw.write(strwebcontent);
                                sw.close();
                        }
                }
                //闪
                private   void   timer1_tick(object   sender,   system.eventargs   e)
                {
                        if   (m_bflag)
                        {
                                this.notifyicon1.icon   =   new   icon( "2.ico ");
                                m_bflag   =   false;
                        }
                        else
                        {
                                this.notifyicon1.icon   =   new   icon( "1.ico ");
                                m_bflag   =   true;
                        }
                }
        }
}
发表于:2007-06-05 16:30:441楼 得分:1
是不是timer1的interver设的太小了?
发表于:2007-06-05 16:38:442楼 得分:0
this.timer1.tick   +=   new   eventhandler(this.timer1_tick);
放到构造函数中
发表于:2007-06-06 09:16:233楼 得分:0
timer1是300
to:jim3(jim)   放到构造函数中啥意思!请举个例子!我是刚学写应用程序!
发表于:2007-06-06 09:29:424楼 得分:0
不要沉啊!高手们帮帮忙啊!在线等啊!解决就给分!
发表于:2007-06-06 13:47:385楼 得分:0
难道没人会吗!
发表于:2007-06-06 14:01:036楼 得分:40
有新的新闻就调用

private   void   notifyuser()
{
        int   counter   =   0;
        while(++counter <=3)
        {
                  notifyicon.icon   =   "新值 ";
                  thread.sleep(100);
                  notifyicon.icon   =   "旧值 ";
                  thread.sleep(100);
          }
}
发表于:2007-06-06 14:36:117楼 得分:0
错误 1 当前上下文中不存在名称“thread”
发表于:2007-06-06 15:08:408楼 得分:0
private   void   notifyuser()
{
        int   counter   =   0;
        while(++counter <=3)
        {
                  notifyicon.icon   =   "新值 ";
                  thread.sleep(100);
                  notifyicon.icon   =   "旧值 ";
                  thread.sleep(100);
          }
}
用这个闪动的时候托盘右键不好用了!必须闪动停下的时候右键菜单才好用!
发表于:2007-06-07 09:20:249楼 得分:0
上去
发表于:2007-06-07 10:06:5910楼 得分:10
public   form1()
{
      initializecomponent();
      this.notifyicon1.icon   =   new   icon( "1.ico ");
      this.sizechanged   +=   new   system.eventhandler(this.form1_sizechanged);
      this.timer2.enabled   =   true;
      this.timer2.tick   +=   new   system.eventhandler(this.timer2_tick);
      //这句放这里
      this.timer1.tick   +=   new   eventhandler(this.timer1_tick);  

}
发表于:2007-06-07 10:38:2011楼 得分:0
1
发表于:2007-06-07 10:43:0912楼 得分:0
干脆用线程来做
发表于:2007-06-07 10:44:1713楼 得分:0
错误1当前上下文中不存在名称“thread”

————————————————————
using   system.threading;
发表于:2007-06-07 10:52:1114楼 得分:0
这是个问题。
发表于:2007-06-07 15:05:5815楼 得分:0
to:jim3(jim)
老大放那里岂不是一运行就闪啊!我是让他有新信息才闪的!
发表于:2007-06-07 17:45:4716楼 得分:0
使用timer1.enabled属性来控制是否闪烁,

你原来的程序多次侦听timer1.tick事件,timer1_tick被多次调用,所以导致你说得现象


发表于:2007-06-08 08:01:0817楼 得分:0
难到timer不能多次用吗!我点显示的时候给他停了!enabled属性我都试过了!


快速检索

最新资讯
热门点击