public partial class Form1 : Form
    {
         System.Timers.Timer t = new System.Timers.Timer();//实例化Timer类,设置间隔时间为毫秒;
      static  Thread f = new Thread(new ThreadStart(ThreadProc));
        //string s;
        //object s1, s2, s3, s4;
        public static  string s5;
        System.Collections.ArrayList AutoTask = new System.Collections.ArrayList();        public Form1()
        {
            InitializeComponent();
        }        private void Form1_Load(object sender, EventArgs e)
        {
            t.Interval = 400;
            t.Elapsed += new System.Timers.ElapsedEventHandler(theout);//到达时间的时候执行事件;
           // t.Elapsed+=new System.Timers.ElapsedEventHandler(tt);
            t.AutoReset = false ;//设置是执行一次(false)还是一直执行(true);
            t.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件;
            System.Collections.ArrayList AutoTask = new System.Collections.ArrayList();            //string ss = System.DateTime.Now.ToString();s = DateTime.Now.ToString("HH:mm");
              
          public partial class Form1 : Form
    {
         System.Timers.Timer t = new System.Timers.Timer();//实例化Timer类,设置间隔时间为毫秒;
      static  Thread f = new Thread(new ThreadStart(ThreadProc));
       
        public Form1()
        {
            InitializeComponent();
        }        private void Form1_Load(object sender, EventArgs e)
        {
            t.Interval = 400;
            t.Elapsed += new System.Timers.ElapsedEventHandler(theout);//到达时间的时候执行事件;
           
            t.AutoReset = false ;//设置是执行一次(false)还是一直执行(true);
            t.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件;
          
           
           
          
                 }
        public static void ThreadProc()
        {          
           
            Form1.stras();
            
                   
            
        }  public void theout(object sender, EventArgs e) {
   
                f.Start();            
}        static  void button1_Click(object sender, EventArgs e)
        {
                      Form1.stras();
           
            
            
        }        private void button2_Click(object sender, EventArgs e)
        {
            button1_Click(button1, EventArgs.Empty);
        }
        private static void  stras()
        {
            Form2 form = new Form2();
            form.HeightMax = 300;//窗体滚动的高度
            form.WidthMax = 148;//窗体滚动的宽度
            form.ScrollShow();
//???????????????????????????????????????
//用 Form1.stras();调用的时候为什么必须执行下面这条语句(MessageBox.Show("www");)才能执行Form2中的time1的事件
// 但是直接点击button2,执行的时候确能正确执行Form2中的time1的事件,正常。
//              MessageBox.Show("www");
//   是不是少触发了什么事件,请高手们指点一下
////??????????????????????            
            
        }              }
               
                f.Start();            //}
          
          
           //MessageBox.Show("ff");
}        static  void button1_Click(object sender, EventArgs e)
        {
           // s5 = textBox5.Text.ToString();            Form1.stras();
           
            
            
        }        private void button2_Click(object sender, EventArgs e)
        {
            button1_Click(button1, EventArgs.Empty);
        }
        private static void  stras()
        {
            Form2 form = new Form2();
            form.HeightMax = 300;//窗体滚动的高度
            form.WidthMax = 148;//窗体滚动的宽度
            form.ScrollShow();
            //MessageBox.Show("www");
            
            //this.Show();
        }                 }

解决方案 »

  1.   

    不好意思刚才贴的比较乱,请看下面这个
        public partial class Form1 : Form 
        { 
            System.Timers.Timer t = new System.Timers.Timer();//实例化Timer类,设置间隔时间为毫秒; 
          static  Thread f = new Thread(new ThreadStart(ThreadProc)); 
          
            public Form1() 
            { 
                InitializeComponent(); 
            }         private void Form1_Load(object sender, EventArgs e) 
            { 
                t.Interval = 400; 
                t.Elapsed += new System.Timers.ElapsedEventHandler(theout);//到达时间的时候执行事件; 
              
                t.AutoReset = false ;//设置是执行一次(false)还是一直执行(true); 
                t.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件; 
              
              
              
              
                    } 
            public static void ThreadProc() 
            {           
              
                Form1.stras(); 
                
                      
                
            }   public void theout(object sender, EventArgs e) { 
      
                    f.Start(); 
                
    }         static  void button1_Click(object sender, EventArgs e) 
            { 
                          Form1.stras(); 
              
                
                
            }         private void button2_Click(object sender, EventArgs e) 
            { 
                button1_Click(button1, EventArgs.Empty); 
            } 
            private static void  stras() 
            { 
                Form2 form = new Form2(); 
                form.HeightMax = 300;//窗体滚动的高度 
                form.WidthMax = 148;//窗体滚动的宽度 
                form.ScrollShow(); 
    //??????????????????????????????????????? 
    //用 Form1.stras();调用的时候为什么必须执行下面这条语句(MessageBox.Show("www");)才能执行Form2中的time1的事件 
    // 但是直接点击button2,执行的时候确能正确执行Form2中的time1的事件,正常。 
    //              MessageBox.Show("www"); 
    //  是不是少触发了什么事件,请高手们指点一下 
    ////??????????????????????            
                
            }           
        } 
                  
                    f.Start(); 
                //} 
              
              
              //MessageBox.Show("ff"); 
    }         static  void button1_Click(object sender, EventArgs e) 
            { 
              // s5 = textBox5.Text.ToString();             Form1.stras(); 
              
                
                
            }         private void button2_Click(object sender, EventArgs e) 
            { 
                button1_Click(button1, EventArgs.Empty); 
            } 
            private static void  stras() 
            { 
                Form2 form = new Form2(); 
                form.HeightMax = 300;//窗体滚动的高度 
                form.WidthMax = 148;//窗体滚动的宽度 
                form.ScrollShow(); 
                //MessageBox.Show("www"); 
                
                //this.Show(); 
            }             
        }
      

  2.   

    public partial class Form1 : Form 
        { 
            System.Timers.Timer t = new System.Timers.Timer();//实例化Timer类,设置间隔时间为毫秒; 
          static  Thread f = new Thread(new ThreadStart(ThreadProc)); 
          
            public Form1() 
            { 
                InitializeComponent(); 
            }         private void Form1_Load(object sender, EventArgs e) 
            { 
                t.Interval = 400; 
                t.Elapsed += new System.Timers.ElapsedEventHandler(theout);//到达时间的时候执行事件; 
              
                t.AutoReset = false ;//设置是执行一次(false)还是一直执行(true); 
                t.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件; 
              
                      } 
            public static void ThreadProc() 
            { 
                Form1.stras(); 
                
            }   public void theout(object sender, EventArgs e) { 
                    f.Start();         
    }         static  void button1_Click(object sender, EventArgs e) 
            { 
                Form1.stras(); 
            }         private void button2_Click(object sender, EventArgs e) 
            { 
                button1_Click(button1, EventArgs.Empty); 
            } 
            private static void  stras() 
            { 
                Form2 form = new Form2(); 
                form.HeightMax = 300;//窗体滚动的高度 
                form.WidthMax = 148;//窗体滚动的宽度 
                form.ScrollShow(); 
    //??????????????????????????????????????? 
    //用 Form1.stras();调用的时候为什么必须执行下面这条语句(MessageBox.Show("www");)才能执行Form2中的time1的事件 
    // 但是直接点击button2,执行的时候确能正确执行Form2中的time1的事件,正常。 
    //              MessageBox.Show("www"); 
    //  是不是少触发了什么事件,请高手们指点一下 
    ////??????????????????????            
                
            } 
        } 
                  
                    f.Start(); 
        //MessageBox.Show("ff"); 
    }         static  void button1_Click(object sender, EventArgs e) 
            { 
              // s5 = textBox5.Text.ToString();             Form1.stras(); 
              
                
                
            }         private void button2_Click(object sender, EventArgs e) 
            { 
                button1_Click(button1, EventArgs.Empty); 
            } 
            private static void  stras() 
            { 
                Form2 form = new Form2(); 
                form.HeightMax = 300;//窗体滚动的高度 
                form.WidthMax = 148;//窗体滚动的宽度 
                form.ScrollShow(); 
                //MessageBox.Show("www"); 
                
                //this.Show(); 
            }         }
      

  3.   

    看起来乱其八糟的,看得也不是特别明白,你在进行定义Timer的时候,是在全局进行的,所以只是在form1 load的情况下进行的,如果你要使用form2的Timer,你需要再次针对form1进行load(用词可能不明白),如果你想直接直接进行使用,需要你考虑一下你的定义位置或者管俩两个form
      

  4.   

    大家感觉有点乱,重新编辑一下
       public partial class Form1 : Form 
        { 
            System.Timers.Timer t = new System.Timers.Timer();//实例化Timer类,设置间隔时间为毫秒; 
          static  Thread f = new Thread(new ThreadStart(ThreadProc)); 
          
            public Form1() 
            { 
                InitializeComponent(); 
            }         private void Form1_Load(object sender, EventArgs e) 
            { 
                t.Interval = 400; 
                t.Elapsed += new System.Timers.ElapsedEventHandler(theout);//到达时间的时候执行事件; 
              
                t.AutoReset = false ;//设置是执行一次(false)还是一直执行(true); 
                t.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件; 
              
              
              
              
                    } 
            public static void ThreadProc() 
            {           
              
                Form1.stras(); 
                
                      
                
            }   public void theout(object sender, EventArgs e) { 
      
                    f.Start(); 
                
    }         static  void button1_Click(object sender, EventArgs e) 
            { 
                          Form1.stras(); 
              
                
                
            }         private void button2_Click(object sender, EventArgs e) 
            { 
                button1_Click(button1, EventArgs.Empty); 
            } 
            private static void  stras() 
            { 
                Form2 form = new Form2(); 
                form.HeightMax = 300;//窗体滚动的高度 
                form.WidthMax = 148;//窗体滚动的宽度 
                form.ScrollShow(); 
    //??????????????????????????????????????? 
    //用 Form1.stras();调用的时候为什么必须执行下面这条语句(MessageBox.Show("www");)才能执行Form2中的time1的事件 
    // 但是直接点击button2,执行的时候确能正确执行Form2中的time1的事件,正常。 
    //              MessageBox.Show("www"); 
    //  是不是少触发了什么事件,请高手们指点一下 
    ////??????????????????????            
                
            }           
        } 
      

  5.   

    FORM1中和FORM2中各有些什么控件?
    Form2中的time1的事件是什么?
    你代码中的Timer t 和f 是在FORM1还是FORM2中?

    你说清楚些啊?
      

  6.   

    这还用看代码吗,,一看就知道什么问题了,MessageBox.Show("www");)这是弹出一个模式对话框,,然后程序就暂停到这里了,直到你点确定和取消,所以你的time1的事件事件无法执行,
      

  7.   

    这还用看代码吗,,一看就知道什么问题了,MessageBox.Show("www");)这是弹出一个模式对话框,,然后程序就暂停到这里了,直到你点确定和取消,所以你的time1的事件事件无法执行,
    是正解
      

  8.   

    from1 load 时,
    每 t.Interval = 400; 
    都启动一个线程?public void theout(object sender, EventArgs e) { 
           f.Start();            

    新线程都会执行 stras()方法吗? 跟一下 public static void ThreadProc() 
            {             Form1.stras(); 
            }