Copy Html To Clipboard

6816 단어 Clipboard
Copy Html To Clipboard는 중국어 부호 문제를 해결합니다.

  
private void CopyHtmlToClipBoard( string html)
{
Encoding enc
= Encoding.UTF8;

string begin = " Version:0.9\r
StartHTML:{0:000000}\r
EndHTML:{1:000000}\r
StartFragment:{2:000000}\r
EndFragment:{3:000000}\r
" ;

string html_begin = " <html>\r
<head>\r
"
+ " <meta http-equiv=\"Content-Type\" "
+ " content=\"text/html; charset= " + enc.WebName + " \">\r
"
+ " <title>HTML clipboard</title>\r
</head>\r
<body>\r
"
+ " <!--StartFragment--> " ;

string html_end = " <!--EndFragment-->\r
</body>\r
</html>\r
" ;

string begin_sample = String.Format(begin, 0 , 0 , 0 , 0 );

int count_begin = enc.GetByteCount(begin_sample);
int count_html_begin = enc.GetByteCount(html_begin);
int count_html = enc.GetByteCount(html);
int count_html_end = enc.GetByteCount(html_end);

string html_total = String.Format(
begin
, count_begin
, count_begin
+ count_html_begin + count_html + count_html_end
, count_begin
+ count_html_begin
, count_begin
+ count_html_begin + count_html
)
+ html_begin + html + html_end;

DataObject obj
= new DataObject();
obj.SetData(DataFormats.Html,
new System.IO.MemoryStream(
enc.GetBytes(html_total)));
Clipboard.SetDataObject(obj,
true );
}

다음으로:http://blog.tcx.be/2005/08/copying-html-fragment-to-clipboard.html

좋은 웹페이지 즐겨찾기