111,129
社区成员
发帖
与我相关
我的任务
分享
private void textBox1_DragEnter(object sender, DragEventArgs e)
{
if ((e.Data.GetDataPresent(DataFormats.Html, false)) || (e.Data.GetDataPresent(DataFormats.Rtf, false)) || (e.Data.GetDataPresent(DataFormats.Text, false)))
{
CanDrog = true;
e.Effect = DragDropEffects.Copy;
}
else
e.Effect = DragDropEffects.None;
}
private void textBox1_DragDrop(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.None;
string strTitle = "";
string strUrl = "";
string strCont = "";
if (CanDrog)
{
if ((e.Data.GetDataPresent(DataFormats.Html, false)) || (e.Data.GetDataPresent(DataFormats.Rtf, false)))
{
Clipboard.SetDataObject(e.Data);
string strMFP = e.Data.GetData(DataFormats.Html, true).ToString();
System.Text.Encoding.Default.GetBytes(strMFP);
System.Text.Encoding gb2312 = System.Text.Encoding.GetEncoding("GB2312");
//byte[] encodedBytes = gb2312.GetBytes(strMFP);
byte[] encodedBytes = System.Text.Encoding.Default.GetBytes(strMFP);
strMFP = System.Text.Encoding.UTF8.GetString(encodedBytes);
Regex regx1 = new Regex(@"<TITLE.*>.*TITLE>", RegexOptions.IgnoreCase);
Match m = regx1.Match(strMFP);
if (m.Success)
{
strTitle = Regex.Replace(m.Value, "<[^>]*>", "").Replace("TITLE>", "");
}
regx1 = new Regex(@"SourceURL:.*", RegexOptions.IgnoreCase);
m = regx1.Match(strMFP);
if (m.Success)
strUrl = m.Value.Substring(10);
}
strCont = e.Data.GetData(DataFormats.Text, true).ToString();
}
}
MemoryStream vMemoryStream =
e.Data.GetData("Html Format") as MemoryStream;
vMemoryStream.Position = 0;
byte[] vBytes = new byte[vMemoryStream.Length];
vMemoryStream.Read(vBytes, 0, (int)vMemoryStream.Length);
textBox1.Text = Encoding.UTF8.GetString(vBytes);