急救:timer事件
我想实现功能是:当时间在12点以下时,图标是一个,当时间在12点以上时,图标换成另外一个,代码如下:
private void timer1_Tick_2(object sender, EventArgs e)
         {
                  DateTime dt = 12;
              if (DateTime.Now.ToString("HH")>dt) //这个函数得到当前小时数.
                  pictureBox1.Image =Image.FromFile(@"Picture\timer-pm.bmp");
              else
                  pictureBox1.Image = Image.FromFile(@"Picture\timer-am.bmp");              
         }
但是运行过程中提示以下二点错误,
Error	1	Cannot implicitly convert type 'int' to 'System.DateTime'	
Error	2	Operator '>' cannot be applied to operands of type 'string' and 'System.DateTime'  
希望得到各位的帮助,兄弟我先谢谢各位啦!
------解决方案--------------------  int dt = 12;
           if (DateTime.Now.TimeOfDay.Hours > dt) //这个函数得到当前小时数.
               pictureBox1.Image = Image.FromFile(@"Picture\timer-pm.bmp");
           else
               pictureBox1.Image = Image.FromFile(@"Picture\timer-am.bmp");
------解决方案--------------------private void timer1_Tick_2(object sender, EventArgs e)  
       {  
                int dt = 12; 
            if (Convert.ToInt32(DateTime.Now.ToString("H"))>dt) //这个函数得到当前小时数. 
            //或 if(DateTime.Now.Hour>dt)
               pictureBox1.Image =Image.FromFile(@"Picture\timer-pm.bmp");  
           else  
               pictureBox1.Image = Image.FromFile(@"Picture\timer-am.bmp");            
       }