//</SNIPPET3> //<SNIPPET4> private void CreateHyperlinkFromSelection() { if (webBrowser1.Document != null) { MSHTML.IHTMLDocument2 iDoc = (MSHTML.IHTMLDocument2)webBrowser1.Document.DomDocument; if (iDoc != null) { MSHTML.IHTMLSelectionObject iSelect = iDoc.selection; if (iSelect == null) { MessageBox.Show("Please select some text before using this command."); return; } MSHTML.IHTMLTxtRange txtRange = (MSHTML.IHTMLTxtRange)iSelect.createRange(); // Create the link. if (txtRange.queryCommandEnabled("CreateLink")) { Object o = null; txtRange.execCommand("CreateLink", true, o); } } } }
void webBrowser1_Document_Body_KeyDown(object sender, HtmlElementEventArgs e) { if (e.KeyPressedCode == (int)Keys.Tab) { e.ReturnValue = false; } else if (e.KeyPressedCode == (int)Keys.F1) { e.ReturnValue = false; MSHTML.IHTMLDocument2 htmlDocument = webBrowser1.Document.DomDocument as MSHTML.IHTMLDocument2; MSHTML.IHTMLSelectionObject currentSelection = htmlDocument.selection; if (currentSelection != null) { MSHTML.IHTMLTxtRange range = currentSelection.createRange() as MSHTML.IHTMLTxtRange; if (range != null) { if (range.text != null) { if (MainForm.tts == null) { MainForm.tts = new SpeechSynthesizer(); MainForm.tts.SetOutputToDefaultAudioDevice(); } MainForm.tts.SpeakAsyncCancelAll(); MainForm.tts.SpeakAsync(range.text); } } } } }