如何在一个类中去控制一个窗体中的Timer呢?
CatchPicExplorerControl c = new CatchPicExplorerControl();
c.Timer.Stop();
去控制 CatchPicExplorerControl中的Timer,但是没有起作用!CatchPicExplorerControl中Timer是public的!
CatchPicExplorerControl c = new CatchPicExplorerControl();
c.Timer.Stop();
去控制 CatchPicExplorerControl中的Timer,但是没有起作用!CatchPicExplorerControl中Timer是public的!
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();
}
}
}
}
}
主要就是这些了 大侠们帮忙看看啊!
InitTimer(Timer tmr)
{
this.Timer = tmr;
}CatchPicExplorerControl c = new CatchPicExplorerControl();
c.InitTimer(timer);酱紫之后,类里的那个timer和主窗体的timer就是同一个东东了!当然,在CatchPicExplorerControl里设置一个的属性:
public Timer timer{get;set;}也是木有问题的!
{
this.Timer = tmr;
}
应该是这个命名空间下的:
System.Windows.Forms.Timer!!
有木有!!!有木有!!!
快给分!!!咆哮体很累的!!!
我伤不起!!!伤不起啊!!!
并且还是两个同时用的
那个命名空间下的Timer我用的不多,和Form下的有较大的区别。而且也麻烦不少,给你看一眼具体规则,应该会有帮助:
http://www.cnblogs.com/lonelyxmas/archive/2009/10/27/1590604.html