CSharp examples for System.Windows.Forms:Clipboard
Clears clipboard and sets the given plain text fragment to the clipboard.
/// The MIT License (MIT) Copyright (c) 2014 Arthur Teplitzki. using System.Windows.Forms; using System.Text; using System;// w w w .ja va2 s. c o m public class Main{ /// <summary> /// Clears clipboard and sets the given plain text fragment to the clipboard.<br/> /// </summary> /// <param name="plainText">the plain text</param> public static void CopyToClipboard(string plainText) { var dataObject = new DataObject(); dataObject.SetData(DataFormats.Text, plainText); dataObject.SetData(DataFormats.UnicodeText, plainText); Clipboard.SetDataObject(dataObject, true); } /// <summary> /// Clears clipboard and sets the given HTML and plain text fragment to the clipboard, providing additional meta-information for HTML.<br/> /// See <see cref="CreateDataObject"/> for HTML fragment details.<br/> /// </summary> /// <example> /// ClipboardHelper.CopyToClipboard("Hello <b>World</b>", "Hello World"); /// </example> /// <param name="html">a html fragment</param> /// <param name="plainText">the plain text</param> public static void CopyToClipboard(string html, string plainText) { var dataObject = CreateDataObject(html, plainText); Clipboard.SetDataObject(dataObject, true); } }