/* * Clipboard -- Copy and Paste */ private void copyToolStripMenuItem_Click(object sender, EventArgs e) { DataObject dataObject; // make certain that a valid link is in the German fields if (string.IsNullOrEmpty(txtDeURL.Text)) { return; } // generate a clipboard envelope string linkHtml = BuildLinkTag(txtDeText.Text, txtDeURL.Text); string env = ClipboardEnvelope.BuildHtmlClipboardEnvelope(linkHtml); dataObject = new DataObject(); dataObject.SetData("HTML Format", env); // put the data on the clipbaord Clipboard.SetDataObject(dataObject); }
private void MainDlg_MouseDown(object sender, MouseEventArgs e) { DataObject dataObject; // make certain that a valid link is in the German fields if (string.IsNullOrEmpty(txtDeURL.Text)) { return; } string linkHtml = BuildLinkTag(txtDeText.Text, txtDeURL.Text); string env = ClipboardEnvelope.BuildHtmlClipboardEnvelope(linkHtml); dataObject = new DataObject(); dataObject.SetData("HTML Format", env); // start a Drag&Drop process _emitingDragDrop = true; DragDropEffects effs = txtDeURL.DoDragDrop(dataObject, DragDropEffects.Copy); _emitingDragDrop = false; }
private void DropHTMLText(string htmlString) { ClearAllLinks(); _curIdx = -1; // in case we don't find any links // set wait cursor Cursor.Current = Cursors.WaitCursor; // unpack the clipboard envelope ClipboardEnvelope env = new ClipboardEnvelope(); if (!env.Read(htmlString)) { return; } string fragment = env.GetFragmentString(); #if true // parse the HTML fragment and extract the <A href=...> element HtmlParser hp = new HtmlParser(fragment); HtmlTag tag; while (hp.ParseNext("a", out tag)) { string url = ""; if (tag.HasAttribute("href")) { url = tag.Attributes["href"]; } string innerText = hp.ParseInnerText(tag); if (url.Length > 0) { string text = System.Web.HttpUtility.HtmlDecode(innerText); Hyperlink hl = new Hyperlink(); hl.uri = url; hl.text = text; // enter the link into the link list _enLinks.Add(hl); } } #else HtmlMiniParser parser = new HtmlMiniParser(fragment); while (parser.ReadTag()) { if (parser.TagName.ToLower() == "a") { string url = ""; while (parser.ReadAttribute()) { if (parser.AttributeName.ToLower() == "href") { url = parser.AttributeValue; break; } } StringBuilder sb = new StringBuilder(); sb.Append(parser.IntraTagText); // consume all intermediate tags until we see the </a> while (parser.ReadTag()) { if (parser.TagName.ToLower() == "/a") { break; } sb.Append(parser.IntraTagText); } if (url.Length > 0) { string text = System.Web.HttpUtility.HtmlDecode(sb.ToString()); Hyperlink hl = new Hyperlink(); hl.uri = url; hl.text = text; // enter the link into the link list _enLinks.Add(hl); } } } #endif // tranlate the links _lt.TranslateLinks2(_enLinks, _deLinks); // show the link and its translations _curIdx = _enLinks.Count > 0 ? 0 : -1; ShowCurrentLink(); // cursor back to normal Cursor.Current = Cursors.Default; }