帮看看这段代码,为啥走不下去了呢

lanqi1983 2010-12-09 08:53:53
public void CodedUITestMethod()
{
this.UIMap.RecordedMethod();
MouseEventArgs e = new MouseEventArgs(MouseButtons.Left,0,0,0,0);
button1_MouseDown(null,e);
atimer.Elapsed+= new ElapsedHandler(timer1_Tick);
}

private bool IsEnd;
System.Timers.Timer atimer = new System.Timers.Timer();

private void button1_MouseDown(object sender,MouseEventArgs e)

{
if(e.Button==MouseButtons.Left)
{
IsEnd=true;
atimer.Interval= 5*1000;
atimer.Enabled= true;
}
}

private void timer1_Tick(object sender,EventArgs e)

{
MouseEventArgs e2 = new MouseEventArgs(MouseButtons.Left,0,0,0,0);

button1_MouseUp(null,e2);

}
private void button1_MouseUp(object sender,MouseEventArgs e)

{
if(e.Button==MouseButtons.Left)
{
IsEnd=false;
atimer.Enabled= false;
}

}


调试时发现只能运行mousedown,后边的mouseup和timer1_Tick都走不到,
...全文
145 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhl8419 2010-12-11
  • 打赏
  • 举报
回复
mouseup事件都没添加。。
wangderong8389945 2010-12-11
  • 打赏
  • 举报
回复
atimer.Enabled= false;
不是true

spiderwolf2010 2010-12-10
  • 打赏
  • 举报
回复
button1_MouseDown(null,e);
atimer.Elapsed+= new ElapsedHandler(timer1_Tick);

以上代码换下顺序试试看。
qiubingzhilian 2010-12-10
  • 打赏
  • 举报
回复
看着有点晕,不过还是学习了
xuzysun 2010-12-10
  • 打赏
  • 举报
回复
照说atimer.Enabled= true也没有问题!
自己跟踪看看好了!!
Cloud_drift 2010-12-10
  • 打赏
  • 举报
回复
我试了下,不用Start()方法也是能跑到的。你说的测试是指单击一下button1吗?

另外,有些奇怪的是,你为什么要用一个Timer把MouseDown和MouseUp连起来呢?
你在进行单击操作的时候,它自己就会先触发MouseDown,然后触发MouseUp的。
huming_h 2010-12-10
  • 打赏
  • 举报
回复
执行atimer 的Start()方法。
lanqi1983 2010-12-10
  • 打赏
  • 举报
回复
没有人吗?同学把我推荐到这里,说有很多高手,结果就是不出来
lanqi1983 2010-12-10
  • 打赏
  • 举报
回复
我的测试是:按住鼠标左键10秒后弹起
所以用了timer,用了楼上的试了下,还是老样子,只调用了mousedown,timer和mouseup还是走不到就调试结束了,执行了start()也还是老样子诶

先谢谢大家的回复

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧