Disable All Events on a Windows Form

后端 未结 5 792
忘了有多久
忘了有多久 2021-01-19 15:21

Is there any way to temporarily disable ALL events on an windows form?

I have situation where processing on a secondary thread is being corrupted by events on the

5条回答
  •  粉色の甜心
    2021-01-19 16:15

    If you want to suppress all events resulting from a PostMessage, then you can implement the IMessageFilter interface and use AddMessageFilter.

    This will probably trap all of the events in which you're interested. It won't trap everything, for example an event resulting from a SendMessage. To trap absolutely everything, you will need a thread-specific application hook.

    Note that this will cause the UI to freeze completely, which may not be what you want. A better apporach might be to intercept the appropriate events and suppress unwanted behaviour while your background work is in progress.

提交回复
热议问题