C# Class exceltk.Clipborad.ClipboardHelper

Helper to encode and set HTML fragment to clipboard.
See
CreateDataObject.
The MIT License (MIT) Copyright (c) 2014 Arthur Teplitzki.
Datei anzeigen Open project: fanfeilong/exceltk

Public Methods

Method Description
CopyToClipboard ( string html, string plainText ) : void

Clears clipboard and sets the given HTML and plain text fragment to the clipboard, providing additional meta-information for HTML.
See CreateDataObject for HTML fragment details.

CreateDataObject ( string html, string plainText ) : DataObject

Create DataObject with given html and plain-text ready to be used for clipboard or drag and drop.
Handle missing ]]> tags, specified startend segments and Unicode characters.

Windows Clipboard works with UTF-8 Unicode encoding while .NET strings use with UTF-16 so for clipboard to correctly decode Unicode string added to it from .NET we needs to be re-encoded it using UTF-8 encoding.

Builds the CF_HTML header correctly for all possible HTMLs
If given html contains start/end fragments then it will use them in the header: hello world]]> If given html contains html/body tags then it will inject start/end fragments to exclude html/body tags: hello world]]> If given html doesn't contain html/body tags then it will inject the tags and start/end fragments properly: world]]> In all cases creating a proper CF_HTML header:
hello world ]]> See format specification here: [http://msdn.microsoft.com/library/default.asp?url=/workshop/networking/clipboard/htmlclipboard.asp][9]

Private Methods

Method Description
GetByteCount ( StringBuilder sb, int start, int end = -1 ) : int

Calculates the number of bytes produced by encoding the string in the string builder in UTF-8 and not .NET default string encoding.

GetHtmlDataString ( string html ) : string

Generate HTML fragment data string with header that is required for the clipboard.

Method Details

CopyToClipboard() public static method

Clears clipboard and sets the given HTML and plain text fragment to the clipboard, providing additional meta-information for HTML.
See CreateDataObject for HTML fragment details.
public static CopyToClipboard ( string html, string plainText ) : void
html string a html fragment
plainText string the plain text
return void

CreateDataObject() public static method

Create DataObject with given html and plain-text ready to be used for clipboard or drag and drop.
Handle missing ]]> tags, specified startend segments and Unicode characters.

Windows Clipboard works with UTF-8 Unicode encoding while .NET strings use with UTF-16 so for clipboard to correctly decode Unicode string added to it from .NET we needs to be re-encoded it using UTF-8 encoding.

Builds the CF_HTML header correctly for all possible HTMLs
If given html contains start/end fragments then it will use them in the header: hello world]]> If given html contains html/body tags then it will inject start/end fragments to exclude html/body tags: hello world]]> If given html doesn't contain html/body tags then it will inject the tags and start/end fragments properly: world]]> In all cases creating a proper CF_HTML header:
hello world ]]> See format specification here: [http://msdn.microsoft.com/library/default.asp?url=/workshop/networking/clipboard/htmlclipboard.asp][9]

public static CreateDataObject ( string html, string plainText ) : DataObject
html string a html fragment
plainText string the plain text
return System.Windows.Forms.DataObject