从剪贴板读取数据乱码问题
以前用这种方读取剪贴板的内容怎么都会有点点乱码,在网上查了很久,终于找到了解决的办法。
1
if (iData.GetDataPresent(DataFormats.Html))
2
{
3
string d = iData.GetData(DataFormats.Html).ToString();
4
textBox1.Text = d;
5
if (listBox1.SelectedItem != null && listBox2.SelectedItem != null)
6
{
7
byte[] b = Encoding.GetEncoding(listBox1.SelectedItem.ToString()).GetBytes(textBox1.Text);
8
textBox2.Text = Encoding.GetEncoding(listBox2.SelectedItem.ToString()).GetString(b);
9
}
10
}
解决办法:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
1
if (Clipboard.ContainsText(TextDataFormat.Html))
2
{
3
MemoryStream vMemoryStream =
4
Clipboard.GetData("Html Format") as MemoryStream;
5
vMemoryStream.Position = 0;
6
byte[] vBytes = new byte[vMemoryStream.Length];
7
vMemoryStream.Read(vBytes, 0, (int)vMemoryStream.Length);
8
textBox1.Text = Encoding.UTF8.GetString(vBytes);
9
}
高兴ing.
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)