开发者

Ctrl + C on Textbox does not work because of global shortcut

开发者 https://www.devze.com 2023-03-03 23:01 出处:网络
I created a numeric textbox and want to implement a custom copy/paste functionality. When override ProcessCmdKey, OnKeyDown or OnKeyPress Ctrl+C is not received, because there is开发者_高级运维 a sho

I created a numeric textbox and want to implement a custom copy/paste functionality.

When override ProcessCmdKey, OnKeyDown or OnKeyPress Ctrl+C is not received, because there is开发者_高级运维 a shortcut in the application defined with the same combination.

Other combinations like Ctrl+U or whatever are received.

Is this even possible? How?


In this case you should override Control.OnPreviewKeyDown and for the case that Ctrl + C is pressed set PreviewKeyDownEventArgs.IsInputKey to true. Doing this should cause Control.OnKeyDown to be called although there is a global shortcut for this key combination.

Update: As my solution does not work for you, the third party library obviously implemented an IMessageFilter which causes the shortcuts to be handled at the message level. You could try to add another message filter and do your custom handling there, nevertheless this will now get ugly...


As Florian pointed out, the message is getting eaten inside of the control somehow, and as you have no direct access to it, you will have to get clever.

This library may be of some use to you, but you will be getting into pretty hacky territory with it as you will have to avoid your normal events (like OnPreviewKeyDown), and use the ones from the lib instead.

http://www.codeproject.com/KB/cs/globalhook.aspx

However if you are trying to capture ctrl+C yourself and do something with it, this is a route you may want to avoid. Users will not expect two things to happen when they hit a shortcut, and they will come after you. Of course, I don't know how or what your app does so that is just a guess.


Set ShortcutsEnabled to false on the control. See TextBoxBase.ShortcutsEnabled.


For me the answer that was striked out worked well. I actually found the solution myself and implemented it but didn't go to compiling for testing, and decided to look for help because the IsInputKey is a very strange name to say that you want to capture the key down.

0

精彩评论

暂无评论...
验证码 换一张
取 消