
When text is copied from MS Word into the Windows clipboard, the clipboard object contains different formats of the copied text. The Windows standard format for formatted text is the Rich Text Format (RTF) which is supported by TX Text Control as well. Sometimes however, it is required to paste the text without formatting into TX Text Control.
To achieve that, MS Word offers a dialog box called "Paste Special". It allows the user to select the format that should be used to insert the clipboard text. This sample shows how to implement such a dialog very easily.
On loading the dialog, it is required to get the different formats that are currently stored in the clipboard. For this purpose, the Clipboard object of the .NET Framework namespace System.Windows.Forms can be used:
if(Clipboard.ContainsText(TextDataFormat.Html))
lbFormats.Items.Add(TextDataFormat.Html);
if (Clipboard.ContainsText(TextDataFormat.Rtf))
lbFormats.Items.Add(TextDataFormat.Rtf);
if (Clipboard.ContainsText(TextDataFormat.Text))
lbFormats.Items.Add(TextDataFormat.Text);
if (Clipboard.ContainsText(TextDataFormat.UnicodeText))
lbFormats.Items.Add(TextDataFormat.UnicodeText);
else
{
lbFormats.Items.Add("No text available");
lbFormats.Enabled = false;
}All supported formats are added to a list box where the user can choose the preferred text format. When the user selects the format and confirms with the OK button, the clipboard content will be loaded into TX Text Control using the selected format:
switch(lbFormats.SelectedItem.ToString())
{
case "Html":
TX.Selection.Load(Clipboard.GetText(TextDataFormat.Html),
TXTextControl.StringStreamType.HTMLFormat);
break;
case "Rtf":
TX.Selection.Load(Clipboard.GetText(TextDataFormat.Rtf),
TXTextControl.StringStreamType.RichTextFormat);
break;
case "Text":
TX.Selection.Text = Clipboard.GetText(TextDataFormat.Text);
break;
case "UnicodeText":
TX.Selection.Load(Clipboard.GetText(TextDataFormat.UnicodeText),
TXTextControl.StringStreamType.PlainText);
break;
}The minimum requirements for this sample application are TX Text Control .NET for Windows Forms trial version and Visual Studio .NET 2005.