开发者

c# catch clipboard changes, wont work if form minimized to tray

开发者 https://www.devze.com 2022-12-24 11:08 出处:网络
i have a problem using the \"Catch Clipboard Events code\" found on this link : Clipboard event C# the code works great only if the form stays in the foreg开发者_Go百科round, not minimized to tray B

i have a problem using the "Catch Clipboard Events code" found on this link :

Clipboard event C#

the code works great only if the form stays in the foreg开发者_Go百科round, not minimized to tray BUT: if you add a notifyicon and minimize the form to tray and turn the showintaskbar to false (so that you only have an icon in the tray), the program wont catch any clipboard changes anymore ... even if you maximize the form back, it wont work again ...you have to restart the program ..

any idea on how to solve this issue !? how can i catch clipboard changes, even if the form is minimized into the tray !?

any help is really appreciated ...

Thanks


It should work if minimized - really minimized though, or hidden. If your implementation of "minimized" invovles destroying the window, then that handle is invalid. And the clipboard chain is now broken for whatever was listening to clipboard events downstream...

Throw some debug code in there to display this.Handle as a string (ex: "123456"). Put the call to SetClipboardViewer in a click event on the form. Click it, see the number. Minimize, restore. Click again. Do you have the same number? you should. If not, then there lies the problem. The clipboard events MUST go to a window that stays around. It can be a hidden window in the background.

-- Chris


So anyway, you could have another form that's hidden, and use that to catch the windows messages. Never close/re-create that window. It opens at startup, stays open, but invisible. This will work.

Chris

0

精彩评论

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

关注公众号