- The Clipboard class is in the name space:System.Windows.Forms
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace Clipboard_Manipulation
{
class Program
{
[STAThread]
static void Main(string [] args)
{
string clipboardContent = string.Empty;
if (Clipboard.ContainsText (TextDataFormat.CommaSeparatedValue))
{
clipboardContent = Clipboard.GetText(TextDataFormat.CommaSeparatedValue );
Clipboard.Clear();
}
else
{
Clipboard.SetText( "This,is,CSV,Data,Just,Placed,On,The,Clipboard",
TextDataFormat.CommaSeparatedValue);
clipboardContent = "<There was no CSV data found on the clipboard>";
}
Console.WriteLine(clipboardContent);
}
}
}
using System;
using System.Windows.Forms;
namespace ClipboardManipulation
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string [] args)
{
Console.WriteLine(GetClipboardContent());
SetClipboardContent("Kevin ");
Console.WriteLine("***************************** ");
Console.WriteLine(GetClipboardContent());
}
public static string GetClipboardContent()
{
IDataObject iData = Clipboard.GetDataObject();
string sResult;
if (iData.GetDataPresent(DataFormats.Text))
{
sResult = iData.GetData(DataFormats.Text).ToString();
}
else
{
sResult = "Could not retrieve data off the clipboard. ";
}
return sResult;
}
public static void SetClipboardContent(string s)
{
Clipboard.SetDataObject(s,true);
}
}
}- a
--
Happy day, happy life!
No comments:
Post a Comment