waitcursor的属性

时间:2011-05-26 11:48:48

标签: c# .net-4.0 dependency-injection ninject custom-attributes

我正在构建一个具有多种形式的应用程序,有时会出现几种情况的等待时间。这些等待时间通常可能是几秒钟,但根据可用性最佳实践,让用户了解正在发生的事情是非常重要的,因此当他必须等待一秒钟或更长时间时,它会让客户高兴知道应用程序正致力于客户/用户行动。

所以我对属性感兴趣。我想要一个属性,我可以应用于我想要的gui中的几种方法。 我不想写

  

this.Cursor = Cursors.WaitCursor;

     

......做点什么......

     

this.Cursor = Cursors.DefaultCursor;

在我的所有方法中。不止一次写东西也违背了最佳做法。

所以...如果有人可以帮助我设置一个属性 this.Cursor = Cursors.WaitCursor;何时调用方法 当方法结束时,属性执行此操作.Cursor = Cursors.DefaultCursor;我会很开心的!

2 个答案:

答案 0 :(得分:2)

查看https://github.com/ninject/ninject.extensions.interception您可以定义在方法调用之前和之后更改光标的属性和拦截器。

答案 1 :(得分:1)

也许您可以按照using类型模式使用WaitCursor?

尝试http://www.codeproject.com/KB/cpp/WaitCursor.aspxhttp://www.codeproject.com/KB/cs/waitcursor.aspx?q=using+waitcursor

using (new StWaitCursor())
{ 
    // .. do some work while WaitCursor is enabled .. 
}

这只有在你有谨慎和非嵌套的程序时才能真正起作用。第一个示例支持堆栈展开,因此您可以嵌套使用块。

希望这有帮助!

相关问题