简体   繁体   中英

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

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 foreground, 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM