在c#中显示线程内的balloontip [英] Show balloontip inside thread in c#

查看:280
本文介绍了在c#中显示线程内的balloontip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目有一个名为inHour的字符串设置,在主窗体中,用户可以更改该字符串,这是一种特定的小时和分钟格式:hh:mm tt。



现在,假设我已将默认小时更改为下午4:50当实时到达该字符串时(通过使用DateTime.Now.ToString(hh:mm tt)== inHour),系统托盘中会显示一个ballontip(通过使用notifyIcon)。



因此,比较时间条件位于FormLoad中启动的线程内。如果时间到达下午4:50 balloontip显示但它仍然可见,因为线程没有停止。



我尝试将int设置为0,然后将其设置为i ++,所以我用了一段时间条件,检查当int i不等于0时它将检查是否是时间显示balloontip但是如果我设置然后i为0线程将不会继续,如果我改变小时再次测试它将无法工作,因为我等于0并且没有再次设置为无限。



那么我怎样才能找到检查时间的方法,显示气球提示并重新开始所有过程?



提前谢谢,CCB

解决方案

您可以使用定时显示而不是每次都在线程中显示:

  var  icon =  new  NotifyIcon (); 
icon.ShowBalloonTip( 1000 气球title 气球文字,ToolTipIcon.None)


My project has a string setting named inHour, and in the main form the user is able to change that string, which is a specific hour and minute formatted this way: hh:mm tt.

Now, let's say I have changed the default hour to 4:50 p.m. When real time reaches that string (by using DateTime.Now.ToString("hh:mm tt") == inHour), a ballontip is shown in the system tray(by using notifyIcon).

So, the comparing time condition is inside a thread that is started at the FormLoad. If time reaches 4:50 p.m. the balloontip shows but it stays visible because the thread has not stopped.

I tried declaring an int set to 0, then set it as i++, so I used a while condition, checking that while int i is not equal to 0 it will check if it is time to show the balloontip but if I set then i to 0 the thread will not continue and if I change the hour to test again it will not work because i is equal to 0 and has not set to infinite again.

So how can I find a way to check for time, show balloontip and start again all the process?

Thanks in advance , CCB

解决方案

You can use timed display instead of showing in thread every time:

var icon = new NotifyIcon();
icon.ShowBalloonTip(1000, "Balloon title", "Balloon text", ToolTipIcon.None)


这篇关于在c#中显示线程内的balloontip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆