Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clipboard Image detected for twice #26

Open
guzelonur opened this issue Mar 10, 2022 · 2 comments
Open

Clipboard Image detected for twice #26

guzelonur opened this issue Mar 10, 2022 · 2 comments

Comments

@guzelonur
Copy link

guzelonur commented Mar 10, 2022

Hi,

I think there might be some bug with the library itself, or the problem might be underlying on System.Windows.Forms.Clipboard class, when I set an image using System.Windows.Forms.Clipboard.SetImage() method, SharpClipboard's ClipboardChanged event is fired TWICE for no reason.

Is there anyone noticed that problem which occurs when you copy/set any image using Clipboard.SetImage() method?

Best regards.

@Mehrdad32
Copy link

Hi everyone, I handled this issue with set and check last object that I get from clipboard and if they were equal I ignore second object!

@MontanaCode
Copy link

MontanaCode commented Apr 2, 2022

The Clipboard.SetImage() method changes the clipboard twice:
1 - It clears the clipboard
2 - It loads the new image into the clipboard.

This is also true of Clipboard.SetText() and others ...

The way I handle this is to create a global class property (integer) called "Ignore". Every time I use the various .Set methods, I first increment (increase) the "Ignore" property by 2. When the WM message comes in (or when SharpClipboard's "ClipboardChanged" event is fired), I have an IF statement, so that it will only process that clipboard message if "ignore" = 0. Each time we ignore a message, we decrement (decrease) the "Ignore" property by 1 after we ignore the message. This will allow us to know when an end-user has copied something new to the clipboard, vs. when we have changed the clipboard ourselves with our code.

Best of luck to all in their coding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants