昨晚和MM一起散步,看到一老人带着他的小可爱狗狗也在散步。MM大叫:“哇,一头长了一身白羽毛的波斯狗!”我当时就被她的一串形容词给搞蒙了,还没等我回过神来,MM又补了一句:“恩,挺像你的!”我倒~我有那么另类吗?哭笑不得啊,表面这么文静的MM,怎么用词这么毒辣啊~~~?

今儿实验室一哥们提了一个BT问题——怎么让控件读数据时鼠标事件不响应?这个问题让我们几个人忙活了半天,还是没有找到合适的答案。MSND上说把Cursor.Current设为Cursors.WaitCursor,可是测试一下根本没有用嘛。然后把this.Cursor设为Cursors.WaitCursor,这回鼠标形状是变成沙漏了,可是仍然会响应鼠标事件。大家都郁闷至极!在CSDN上看帖子查查,我在一个和这个问题八不沾边的帖子里看了一个想法,让大家都兴奋起来。呵呵……这个想法很BT,简直就是一头长了一身白羽毛的波斯狗!总结一下就是当控件开始读数据时,建一个放在最上层的全屏透明WinForm盖着屏幕就OK了,最后等数据读完再把这个临时窗体清了。当然鼠标形状在这个过程也响应的变化。这个BT骗术,现在看来还不错,问题很好的解决了。我想MSDN一定有更直接的解决方法,但是我是没找到,等高人指点了!希望部署程序的时候能用常规的方法来处理这个问题,不能让用户花钱买”一头长了一身白羽毛的波斯狗“吧,嘿嘿……


2条评论

  1. When I set the current cursor to the wait cursor, why does it revert before I want it to?

    I set the wait cursor using Cursor.Current = Cursors.WaitCursor;. Why does does it disappear before I want it to?

    Setting the Current property changes the cursor and stops the processing of mouse events. Setting the cursor back to Cursors.Default restarts the mouse event processing and displays the proper cursor for each control. If a DoEvents is called before you reset the cursor back to the default, this will also start up the mouse event processing and you will lose the particular cursor you set. So, if your WaitCursor is disappearring, one explanation might be that DoEvents is getting called.

    Here is some code that sets a WaitCursor.

    Cursor oldCursor = Cursor.Current;

    Cursor.Current = Cursors.WaitCursor;

    try

    {

    // Do your processing that takes time, e.g., wait for 2 seconds

    DateTime dt = DateTime.Now.AddSeconds(2);

    while ( dt > DateTime.Now ) {}

    }

    finally

    {

    Cursor.Current = oldCursor;

    }

    Contributed from George Shepherd’s Windows Forms FAQ

  2. Hi, scdch, thanx for ur feedback!

    The method, in ur feedback, is very good! But when I use it in different code block, I get the different result. e.g: using button_click event to call the method, it can return OK result; using form_load event to call it, null/nothing can be returned. How to call the method correctly?

发表评论

评论也有版权!

click to change验证码