CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  C#

要做时间为5:30的时候,程序就会弹出对话框,请大家给点思路

楼主l444333(33333333333333333333333333333333333333333333333333)2006-11-06 20:07:07 在 .NET技术 / C# 提问

要做时间为5:30的时候,就会弹出提示的对话框,请大家给点思路  
   
  比如:到了下午5:30,程序会自动弹出一个对话框。  
   
  要求:1.程序主界面可以自由设定弹出对话框的时间。  
              2.可以设定弹出对话框的内容(提示信息),如"现在是5:30半了,下班时间到了"   。  
              3.点击最小化后,程序就会在托盘里显示,就像QQ或msn那样的。  
              4.数据库用xml.  
              5.开发语言用.net2.0   和C#   2.0,vs2005.  
   
   
  请大家给点思路或步骤,该先做什么,再做什么,或者第一步做什么,第二步做什么,  
   
  谢谢!  
  问题点数:100、回复次数:29Top

1 楼smartstar2005()回复于 2006-11-06 20:11:39 得分 0

还用得上数据库?  
   
  莫非是我的理解肤浅了?Top

2 楼viena(维也纳N02)回复于 2006-11-06 20:13:59 得分 0

@_@Top

3 楼yourname386(菜了)回复于 2006-11-06 20:14:44 得分 0

用timer应可以搞定Top

4 楼lizhizhe2000(武安侯)回复于 2006-11-06 20:18:35 得分 10

1。时间控制用Timer控件吧  
  2.托盘用NotifiIcon控件  
  3.没必要用数据库Top

5 楼YYGui()回复于 2006-11-06 20:22:05 得分 0

数据库是有必要```  
  从XML里面取出之前存的弹出对话框的时间``  
  然后由Timer判断现在时间跟所保存的时间是否相等``  
  托盘用NotifiIcon控件就行了``Top

6 楼smartstar2005()回复于 2006-11-06 20:24:13 得分 5

那也不用数据库吧?  
   
  一个变量就行了。  
   
  实现方法大家都说的很清楚了啊  
   
  共享Top

7 楼YYGui()回复于 2006-11-06 20:51:30 得分 0

那就是每次都得设置一下???  
  他所说的数据库的概念就是一个XML```  
  直接取出来赋值就行了的``Top

8 楼lovvver(ElephantTalk.Bright)回复于 2006-11-06 21:16:34 得分 45

定时操作可以使用System.Timers.Timer,  
  可以设定的话,你可以放到config配置文件中。  
  关闭到托盘,可以使用NotifyIcon。  
   
  这里面关闭到托盘的实现可能会觉得复杂一点,给你个例子:  
  Top

9 楼pshy(无心)回复于 2006-11-06 21:23:21 得分 0

我跑進來等例子........  
  :)Top

10 楼lovvver(ElephantTalk.Bright)回复于 2006-11-06 21:28:30 得分 0

//首先,需要两个控件:NotifyIcon,ContextMenu(Open,Exit)  
  private   System.Windows.Forms.NotifyIcon   _notifyIcon;  
  private   System.Windows.Forms.ContextMenu   _contextMenu;  
  private   System.Windows.Forms.MenuItem   _openMenuItem;  
  private   System.Windows.Forms.MenuItem   _exitMenuItem;  
  this._notifyIcon   =   new   System.Windows.Forms.NotifyIcon(this.components);  
  this._contextMenu   =   new   System.Windows.Forms.ContextMenu();  
  this._openMenuItem   =   new   System.Windows.Forms.MenuItem();  
  this._exitMenuItem   =   new   System.Windows.Forms.MenuItem();  
  //    
  //   _notifyIcon  
  //    
  this._notifyIcon.ContextMenu   =   this._contextMenu;  
  this._notifyIcon.Icon   =   ((System.Drawing.Icon)(resources.GetObject("_notifyIcon.Icon")));  
  this._notifyIcon.Text   =   "XXX";  
  this._notifyIcon.Visible   =   true;  
  this._notifyIcon.DoubleClick   +=   new   System.EventHandler(this._notifyIcon_DoubleClick);  
  //    
  //   _contextMenu  
  //    
  this._contextMenu.MenuItems.AddRange(new   System.Windows.Forms.MenuItem[]   {   this._openMenuItem,   this._exitMenuItem}   );  
   
   
  //    
  //   _openMenuItem  
  //    
  this._openMenuItem.Index   =   0;  
  this._openMenuItem.Text   =   "&Open   XE   Currency   Service   Manager";  
  this._openMenuItem.Click   +=   new   System.EventHandler(this._openMenuItem_Click);  
  //    
  //   _exitMenuItem  
  //    
  this._exitMenuItem.Index   =   7;  
  this._exitMenuItem.Text   =   "&Exit";  
  this._exitMenuItem.Click   +=   new   System.EventHandler(this._exitMenuItem_Click);  
   
  //重写几个窗体事件  
  #region   Override   Methods  
  protected   override   void   WndProc(ref   Message   m)  
  {  
  const   int   WM_SYSCOMMAND   =   0x0112;  
  const   int   SC_CLOSE   =   0xF060;  
  if   (m.Msg   ==   WM_SYSCOMMAND   &&   (int)   m.WParam   ==   SC_CLOSE)  
  {  
  //   User   clicked   close   button  
  this.Visible   =   false;  
  return;  
  }  
  base.WndProc   (ref   m);  
  }  
   
  protected   override   void   OnClosed(EventArgs   e)  
  {  
  this._notifyIcon.Visible   =   false;  
  this._notifyIcon.Icon   .Dispose   ();  
  this._notifyIcon.Dispose();    
  base.OnClosed   (e);  
  }  
  #endregion  
   
  //菜单项事件  
  private   void   _openMenuItem_Click(object   sender,   System.EventArgs   e)  
  {  
  AutoScaleBaseSize   =   new   System.Drawing.Size(5,   15);  
  ClientSize   =   new   System.Drawing.Size(554,   316);  
  Visible   =   true;  
  }  
   
  private   void   _exitMenuItem_Click(object   sender,   System.EventArgs   e)  
  {  
  if(MessageBox.Show("Confirm   to   exit?","Exit",MessageBoxButtons.OKCancel   ,MessageBoxIcon.Question   ,MessageBoxDefaultButton.Button1)   ==   DialogResult.OK)  
  {  
  this._notifyIcon.Visible   =   false;  
  this._notifyIcon.Icon   .Dispose   ();  
  this._notifyIcon.Dispose();    
  base.OnClosed   (e);  
  Application.Exit()   ;  
  }  
  }  
  //NotifyIcon双击事件  
  private   void   _notifyIcon_DoubleClick(object   sender,   System.EventArgs   e)  
  {  
  AutoScaleBaseSize   =   new   System.Drawing.Size(5,   15);  
  ClientSize   =   new   System.Drawing.Size(554,   316);  
  Visible   =   true;  
  }Top

11 楼lovvver(ElephantTalk.Bright)回复于 2006-11-06 21:30:35 得分 0

楼主可以新建一个Application,在窗体里把以上代码拷贝进去。然后编译运行测试。  
  这是如何关闭到托盘的例子,至于定时处理,那就比较简单了,就不帖啦Top

12 楼lovvver(ElephantTalk.Bright)回复于 2006-11-06 21:50:31 得分 0

以上代码需要修改的地方:  
  1。this._exitMenuItem.Index   =   7;->this._exitMenuItem.Index   =   1;  
  2。你需要给NotifyIcon添加一个icon(.ico图片,以显示在托盘上)  
  3。this._notifyIcon.Icon   =   ((System.Drawing.Icon)(resources.GetObject("_notifyIcon.Icon")));  
  该句去掉,其是设置icon图片的,你可以在你本地手动添加ico图片。  
  注意的地方:  
  1。组建声明部分,要拷贝到this.components   =   new   System.ComponentModel.Container();和Form属性设置的中间。  
  以防止this._notifyIcon   =   new   System.Windows.Forms.NotifyIcon(this.components);该句引用的components为null。Top

13 楼lovvver(ElephantTalk.Bright)回复于 2006-11-06 21:52:58 得分 0

//测代码:NotifyIconTest.cs  
  using   System;  
  using   System.Drawing;  
  using   System.Collections;  
  using   System.ComponentModel;  
  using   System.Windows.Forms;  
  using   System.Data;  
   
  namespace   NotifyIconTest  
  {  
  ///   <summary>  
  ///   Form1   的摘要说明。  
  ///   </summary>  
  public   class   Form1   :   System.Windows.Forms.Form  
  {  
  private   System.ComponentModel.IContainer   components;  
  //首先,需要两个控件:NotifyIcon,ContextMenu(Open,Exit)  
  private   System.Windows.Forms.NotifyIcon   _notifyIcon;  
  private   System.Windows.Forms.ContextMenu   _contextMenu;  
  private   System.Windows.Forms.MenuItem   _openMenuItem;  
  private   System.Windows.Forms.MenuItem   _exitMenuItem;  
   
   
  public   Form1()  
  {  
  //  
  //   Windows   窗体设计器支持所必需的  
  //  
  InitializeComponent();  
   
  //  
  //   TODO:   在   InitializeComponent   调用后添加任何构造函数代码  
  //  
  }  
   
  ///   <summary>  
  ///   清理所有正在使用的资源。  
  ///   </summary>  
  protected   override   void   Dispose(   bool   disposing   )  
  {  
  if(   disposing   )  
  {  
  if   (components   !=   null)    
  {  
  components.Dispose();  
  }  
  }  
  base.Dispose(   disposing   );  
  }  
   
  #region   Windows   窗体设计器生成的代码  
  ///   <summary>  
  ///   设计器支持所需的方法   -   不要使用代码编辑器修改  
  ///   此方法的内容。  
  ///   </summary>  
  private   void   InitializeComponent()  
  {  
  this.components   =   new   System.ComponentModel.Container();  
  System.Resources.ResourceManager   resources   =   new   System.Resources.ResourceManager(typeof(Form1));  
  this._notifyIcon   =   new   System.Windows.Forms.NotifyIcon(this.components);  
  this._contextMenu   =   new   System.Windows.Forms.ContextMenu();  
  this._openMenuItem   =   new   System.Windows.Forms.MenuItem();  
  this._exitMenuItem   =   new   System.Windows.Forms.MenuItem();  
  //    
  //   _notifyIcon  
  //    
  this._notifyIcon.ContextMenu   =   this._contextMenu;  
  this._notifyIcon.Icon   =   ((System.Drawing.Icon)(resources.GetObject("_notifyIcon.Icon")));  
  this._notifyIcon.Text   =   "XXX";  
  this._notifyIcon.Visible   =   true;  
  this._notifyIcon.DoubleClick   +=   new   System.EventHandler(this._notifyIcon_DoubleClick);  
  //    
  //   _contextMenu  
  //    
  this._contextMenu.MenuItems.AddRange(new   System.Windows.Forms.MenuItem[]   {  
    this._openMenuItem,  
    this._exitMenuItem});  
  //    
  //   _openMenuItem  
  //    
  this._openMenuItem.Index   =   0;  
  this._openMenuItem.Text   =   "&Open";  
  this._openMenuItem.Click   +=   new   System.EventHandler(this._openMenuItem_Click);  
  //    
  //   _exitMenuItem  
  //    
  this._exitMenuItem.Index   =   1;  
  this._exitMenuItem.Text   =   "&Exit";  
  this._exitMenuItem.Click   +=   new   System.EventHandler(this._exitMenuItem_Click);  
  //    
  //   Form1  
  //    
  this.AutoScaleBaseSize   =   new   System.Drawing.Size(6,   14);  
  this.ClientSize   =   new   System.Drawing.Size(292,   262);  
  this.Icon   =   ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));  
  this.Name   =   "Form1";  
  this.Text   =   "Form1";  
   
  }  
  #endregion  
   
  ///   <summary>  
  ///   应用程序的主入口点。  
  ///   </summary>  
  [STAThread]  
  static   void   Main()    
  {  
  Application.Run(new   Form1());  
  }  
  #region   Override   Methods  
  protected   override   void   WndProc(ref   Message   m)  
  {  
  const   int   WM_SYSCOMMAND   =   0x0112;  
  const   int   SC_CLOSE   =   0xF060;  
  if   (m.Msg   ==   WM_SYSCOMMAND   &&   (int)   m.WParam   ==   SC_CLOSE)  
  {  
  //   User   clicked   close   button  
  this.Visible   =   false;  
  return;  
  }  
  base.WndProc   (ref   m);  
  }  
   
  protected   override   void   OnClosed(EventArgs   e)  
  {  
  this._notifyIcon.Visible   =   false;  
  this._notifyIcon.Icon   .Dispose   ();  
  this._notifyIcon.Dispose();    
  base.OnClosed   (e);  
  }  
  #endregion  
   
  //菜单项事件  
  private   void   _openMenuItem_Click(object   sender,   System.EventArgs   e)  
  {  
  AutoScaleBaseSize   =   new   System.Drawing.Size(5,   15);  
  ClientSize   =   new   System.Drawing.Size(554,   316);  
  Visible   =   true;  
  }  
   
  private   void   _exitMenuItem_Click(object   sender,   System.EventArgs   e)  
  {  
  if(MessageBox.Show("Confirm   to   exit?","Exit",MessageBoxButtons.OKCancel   ,MessageBoxIcon.Question   ,MessageBoxDefaultButton.Button1)   ==   DialogResult.OK)  
  {  
  this._notifyIcon.Visible   =   false;  
  this._notifyIcon.Icon   .Dispose   ();  
  this._notifyIcon.Dispose();    
  base.OnClosed   (e);  
  Application.Exit()   ;  
  }  
  }  
  //NotifyIcon双击事件  
  private   void   _notifyIcon_DoubleClick(object   sender,   System.EventArgs   e)  
  {  
  AutoScaleBaseSize   =   new   System.Drawing.Size(5,   15);  
  ClientSize   =   new   System.Drawing.Size(554,   316);  
  Visible   =   true;  
  }  
   
  }  
  }  
  Top

14 楼lyred(Amazing aNd Undescribable)回复于 2006-11-06 21:59:57 得分 0

mark一下,Top

15 楼xuwei(夕阳西下,断肠人在天涯)回复于 2006-11-06 22:15:59 得分 0

长见识了Top

16 楼fish_yht(百行孝为先,万业勤为径。)回复于 2006-11-06 22:30:00 得分 0

学习了Top

17 楼free_wang()回复于 2006-11-07 13:17:03 得分 0

学习了Top

18 楼beijingbeerman(啤酒肚)回复于 2006-11-07 14:43:27 得分 0

markTop

19 楼Qim(莫名-从星做起......)回复于 2006-11-07 16:34:22 得分 0

以前做了一个,提示时间和新邮件的小程序。邮件可以自己设定。  
  楼主要。我发给你。Top

20 楼xsp521()回复于 2006-11-07 16:35:30 得分 40

DateTime   dt   =   Convert.ToDateTime   ("2006-11-7   16:00:00");  
                private   void   button1_Click(object   sender,   EventArgs   e)  
                  {  
                          MessageBox.Show(DateTime.Now   .ToString   ());  
                  }  
   
                  private   void   timer1_Tick(object   sender,   EventArgs   e)  
                  {  
                          if   (DateTime.Now.ToString   ()==dt.ToString   ())  
                          {  
                                  MessageBox.Show("ssss");  
                          }  
                  }  
   
                  private   void   Form1_Load(object   sender,   EventArgs   e)  
                  {  
                          timer1.Start();  
                  }  
   
                  private   void   Form1_FormClosing(object   sender,   FormClosingEventArgs   e)  
                  {  
                          timer1.Stop();  
                  }  
   
                  private   void   notifyIcon1_MouseDoubleClick(object   sender,   MouseEventArgs   e)  
                  {  
   
                  }  
   
                  private   void   notifyIcon1_Click(object   sender,   EventArgs   e)  
                  {  
                          this.Visible   =   true;  
                          this.WindowState   =   FormWindowState.Normal;  
                          this.notifyIcon1.Visible   =   false;  
                  }  
   
                  private   void   Form1_Resize(object   sender,   EventArgs   e)  
                  {  
                          if   (this.WindowState   ==   FormWindowState.Minimized)  
                          {  
                                  this.Visible   =   false;  
                                  this.notifyIcon1.Visible   =   true;  
                          }  
   
   
                  }Top

21 楼zerohk(零度空间)回复于 2006-11-07 16:53:26 得分 0

sdmTop

22 楼bbdog(贝贝狗)回复于 2006-11-07 18:02:15 得分 0

收藏了先,吃完饭后来详读.Top

23 楼shenyang523()回复于 2006-11-07 18:35:07 得分 0

perfect  
  Top

24 楼vosov(ask a favor of wind...)回复于 2006-11-07 19:01:17 得分 0

哈,俺做过这个东西  
  上班时候玩的。每隔1小时跳出来提醒俺休息一下Top

25 楼leobaby()回复于 2006-11-07 19:04:32 得分 0

顶一个  
  学习Top

26 楼antoniusguo(anton)回复于 2006-11-07 20:07:28 得分 0

哈,俺做过这个东西  
  上班时候玩的。每隔1小时跳出来提醒俺休息一下  
   
  ............................................  
   
  做个服务每小时重启一次,强制休息Top

27 楼swing05(飞翔)回复于 2006-11-07 21:06:51 得分 0

mark!Top

28 楼tipboy(想做技术边缘人)回复于 2006-11-08 09:02:36 得分 0

呵呵Top

29 楼zhudiyouyou(竹笛悠悠)回复于 2006-11-08 10:02:05 得分 0

antoniusguo(anton)   (   )   信誉:100         Blog     2006-11-7   20:07:28     得分:   0      
     
     
         
  哈,俺做过这个东西  
  上班时候玩的。每隔1小时跳出来提醒俺休息一下  
   
  ............................................  
   
  做个服务每小时重启一次,强制休息  
   
       
  ............................................  
   
  这个强!!!Top

相关问题

关键词

得分解答快速导航

  • 帖主:l444333
  • lizhizhe2000
  • smartstar2005
  • lovvver
  • xsp521

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo