views:

65

answers:

3

I have an application where i am using Clipboard for copy, paste operations. For copying i have used this code

Clipboard.Clear();
const byte VK_CONTROL = 0x11;
keybd_event(VK_CONTROL, 0, 0, 0);
keybd_event(0x43, 0, 0, 0); //Send the C key (43 is "C")
keybd_event(0x43, 0, CONST_KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, 0, CONST_KEYEVENTF_KEYUP, 0);

But it's giving an error saying Unable to Perform the Clipboard Action and I am unable to paste it.It's throwing an exception.

Can anybody please help me to fix this issue or Please suggest some other ways to clear the Clipboard content before we copy.

+1  A: 

Any reason you aren't using

Clipboard.SetText("some string");
Clipboard.GetText();

MSDN article here

Arkain
Basically i am trying to overwrite the CTRL+C functionality in my application. i.e., whenever us er presses hot key, then the selected text should be copied into clipboard. I don't know, what the user going to select, so i can't use setText.
Dinesh
A: 
Clipboard.Clear()

MSDN

Homam
A: 

I have done it using Win32 API calls(EmptyClipboard function).

Dinesh