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

2

6

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

Havstad answered 21/3, 2010 at 23:50 Comment(0)
B
1

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

Billmyre answered 22/3, 2010 at 1:29 Comment(3)
So, did you try my idea, and if so, did the handle remain constant, or did it change?Billmyre
hi Chris ... sorry have been away the whole last week .. i will give it a try, but i did try smthg like this before .. the idea with the invisible form is good, i will try it and tell you .. thanks againHavstad
NP - I'm glad you're still alive. Let me know.Billmyre
B
1

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

Billmyre answered 23/3, 2010 at 3:7 Comment(2)
hi Chris .. i just finished trying your suggestion, and it works ... iam not sure, but it seems to be that the this.ShowInTaskbar=false; will kill the form, or at least in my condition the handle will become invalid .. so just minimize to tray, and it works great :) thanks again for the helpHavstad
Great! Don't forget to upvote and accept. If the trick about displaying the handle ID helped, upvote that one and leave this one to rot. Thanks.Billmyre

© 2022 - 2024 — McMap. All rights reserved.