Copy/Paste in menu

  • Thread starter Thread starter alunharford
  • Start date Start date
A

alunharford

I have a reasonably sized MDI application, where some of the MDI
children are opened by plugins whose code I (potentially) have no
control over.
If I press control+c, the text I want to copy is copied to the
clipboard (presumably by some magic in the .NET framework that handles
this). If I press control+v, it's also pasted, exactly as I want it.
That's great.

I'd like to add an 'Edit' menu to this application. When the user
clicks 'Copy', I want the application to do exactly what is done by
control+c (which works fine). Does anybody have any tips on how this
is done?
 
Try using the following code snippet

public void CopyToClipboard()
{

IDataObject dataObj = new DataObject();
dataObj.SetData(DataFormats.Text, false, this);
Clipboard.SetDataObject(dataObj, false);

//that's it
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top