Copy Html To Clipboard

Copy Html To Clipboard 可解决中文乱码问题。

复制代码
  
  
private void CopyHtmlToClipBoard( string html)
{
Encoding enc
= Encoding.UTF8;

string begin = " Version:0.9\r\nStartHTML:{0:000000}\r\nEndHTML:{1:000000}\r\nStartFragment:{2:000000}\r\nEndFragment:{3:000000}\r\n " ;

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

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值