如何在一个类中去控制一个窗体中的Timer呢?
    CatchPicExplorerControl c = new CatchPicExplorerControl();
    c.Timer.Stop();
   去控制 CatchPicExplorerControl中的Timer,但是没有起作用!CatchPicExplorerControl中Timer是public的!

解决方案 »

  1.   

    在那个窗体发布一个属性,来控制timer,或者将timer的modifer属性改为public,这样既可以通过窗体实例直接访问timer了
      

  2.   

      CatchPicExplorerControl中Timer是public的!我在类用CatchPicExplorerControl.Timer.Stop(),TImer计时没有停止!
      

  3.   

    在中msdn找找,估计对你有帮助。
      

  4.   

       CatchPicExplorerControl控件中:  public System.Timers.Timer timer_1;
      public CatchPicExplorerControl(){
          timer_1 = new System.Timers.Timer(5000);
          timer_1.Elapsed += new System.Timers.ElapsedEventHandler(timer_1_Elapsed);
      }   void timer_1_Elapsed (object sender, System.Timers.ElapsedEventArgs e)
            {
                timer_1.Stop();
                try
                {
                   if (ModuleManager.Instance.Context.LoginState != LoginState.Logined)
                    {
                        timer_1.Stop();
                        timer_1.Dispose();
                        LoggingService.Info("timer_1_Stop:用户注销后停止定时抓图!");
                        return;
                    }                ManagePicture();
                    if (edList.Count == 0)
                    {
                        timer_1.Stop();
                        return;
                    }
                    else
                    {
                        OnItemDoAction(this, new IDNameEventArgs(edList[0] as CameraDevice));
                    }
                }
                catch (Exception ex)
                {
                    LoggingService.Error(ex);
                    timer_1.Stop();
                    return;
                }
                timer_1.Start();
            }      一button按钮事件中:timer_1.Start();当点击按钮时启动
     public class CatchPicVedioFormEnd : AbstractMenuCommand
        {
            public override void Run ()
            {
                CatchPicExplorerControl c = new CatchPicExplorerControl();
                c.timer_1.Enabled = true;//刚开始的时候没有加,后来加上的,还是没用!
                c.timer_1.Stop();
                IViewGroup viewGroup = VideoViewContentZJP.Instance.ViewGroup;
                foreach (IPlay player in viewGroup.Items)
                {
                    if (player is ControlViewPlay)
                    {
                        if ((player as ControlViewPlay).IsPlaying)
                        {
                            (player as ControlViewPlay).Stop();
                        }
                    }
                }
            }
        }
       主要就是这些了   大侠们帮忙看看啊!
      

  5.   

    这个很简单,在CatchPicExplorerControl类中添加一个方法,和一个全局Timer:Timer Timer;
    InitTimer(Timer tmr)
    {
       this.Timer = tmr;
    }CatchPicExplorerControl c = new CatchPicExplorerControl();
    c.InitTimer(timer);酱紫之后,类里的那个timer和主窗体的timer就是同一个东东了!当然,在CatchPicExplorerControl里设置一个的属性:
    public Timer timer{get;set;}也是木有问题的!
      

  6.   

    public void InitTimer(Timer tmr)
    {
      this.Timer = tmr;
    }
      

  7.   

    小哥你Timer用错了!!!
    应该是这个命名空间下的:
    System.Windows.Forms.Timer!!
    有木有!!!有木有!!!
    快给分!!!咆哮体很累的!!!
    我伤不起!!!伤不起啊!!!
      

  8.   

       就是这个命名空间public System.Timers.Timer timer_1;
       并且还是两个同时用的
      

  9.   


    那个命名空间下的Timer我用的不多,和Form下的有较大的区别。而且也麻烦不少,给你看一眼具体规则,应该会有帮助:
    http://www.cnblogs.com/lonelyxmas/archive/2009/10/27/1590604.html