private void btnPrint_Click(object sender, RoutedEventArgs e) { // Získání objektu z prohlížeče k tisku mshtml.IHTMLDocument2 doc = webBrowser1.Document as mshtml.IHTMLDocument2; if (ExportType == ExportType.HTML) { Print(doc); } // Soubor .xml se vždy vytiskne jako prázdná stránka, proto je potřeba převést i XML na HTML pro tisk if (ExportType == ExportType.XML) { // je nutné nahradit speciální znaky ze xml: (< <),(> >); string alteredXml = _displayXmlTree; alteredXml = alteredXml.Replace("<", "<"); alteredXml = alteredXml.Replace(">", ">"); string html = $@" <html> <head> <meta charset=""utf-8"" /> <title>Xml</title> </head> <body> <pre> {alteredXml} </pre> </body > </html>"; // nejdříve načteme xml ve fromě html do prohlížeče a po skončení tisku zobrazíme čisté xml zpět webBrowser1.NavigateToString(html); webBrowser1.LoadCompleted += InvokePrintReturnToXmlAfterFinished; } }
private void Print(mshtml.IHTMLDocument2 doc) { if (doc != null) { // Aby se stránka vytiskla bez hlavičky a patičky, tak je potřeba to upravit v nastevení IE v registrech // Po skončení tisku jsou registry obnoveny do původní podoby try { const string keyName = @"Software\Microsoft\Internet Explorer\PageSetup"; using (var key = Registry.CurrentUser.OpenSubKey(keyName, true)) { if (key != null) { var oldFooter = key.GetValue("footer"); var oldHeader = key.GetValue("header"); key.SetValue("footer", ""); key.SetValue("header", ""); doc.execCommand("Print", true, null); key.SetValue("footer", oldFooter); key.SetValue("header", oldHeader); return; } } } catch { } // při chybě úpravy registrů bude mít export nežádoucí hlavičku - alespoň se ale tisk podaří doc.execCommand("Print", true, null); } }
public clsSnoTelStateTable(string url) { URL = url; WebClient client = new WebClient(); byte[] data = client.DownloadData(URL); mshtml.HTMLDocumentClass Doc = new mshtml.HTMLDocumentClass(); string sHtml = System.Text.Encoding.ASCII.GetString(data); mshtml.IHTMLDocument2 oDoc = (mshtml.IHTMLDocument2)Doc; oDoc.write(sHtml); bool tableFound = false; foreach (mshtml.IHTMLElement element in (mshtml.IHTMLElementCollection)oDoc.body.all) { if (element is mshtml.HTMLPhraseElement && element.innerText == "Status") { tableFound = true; } else if (element is mshtml.HTMLTableClass && tableFound && element.innerText.Contains("Site Map")) { tableFound = false; } else if (element is mshtml.HTMLTableRowClass && tableFound) { Records.Add(new SnoTelRecord((mshtml.HTMLTableRowClass)element, Records.Count)); } } }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Retrieve cookie from opened IE window. It doesn't renew setting if no opened official page /// exists. /// </summary> //////////////////////////////////////////////////////////////////////////////////////////////////// private void SweepCookie() { var shellWindows = new SHDocVw.ShellWindows(); string longestCookie = string.Empty; foreach (SHDocVw.WebBrowser wb in shellWindows) { var url = new Uri(wb.LocationURL); if (url.Host == "osu.ppy.sh") { mshtml.IHTMLDocument2 doc2 = (mshtml.IHTMLDocument2)wb.Document; if (longestCookie.Length < doc2.cookie.Length) { longestCookie = doc2.cookie; } } } if (longestCookie == string.Empty) { if (Timer.IsEnabled) { Timer.Stop(); } return; } var setting = Properties.Settings.Default; if (setting.OfficialSession != longestCookie) { setting.OfficialSession = longestCookie; } }
private void _initHtmlEditor() { HtmlEditor.Navigate("about:blank"); _htmlDoc = HtmlEditor.Document.DomDocument as mshtml.IHTMLDocument2; _htmlDoc.designMode = "on"; _initFonts(); }
public static SHDocVw.InternetExplorer GetIEFromHWnd(int hIEWindow, out mshtml.IHTMLDocument2 currDoc) { Guid IID_IWebBrowser2 = typeof(SHDocVw.InternetExplorer).GUID; Guid IID_IServiceProvider = typeof(Microsoft.VisualStudio.OLE.Interop.IServiceProvider).GUID; Guid IID_IHTMLDocument2 = typeof(mshtml.IHTMLDocument2).GUID; Guid IID_IHTMLWindow2 = typeof(mshtml.IHTMLWindow2).GUID; Guid SID_SWebBrowserApp = typeof(SHDocVw.IWebBrowserApp).GUID; int hWnd = hIEWindow; int lRes = 0; mshtml.IHTMLDocument2 spDoc = null; int lngMsg = RegisterWindowMessage("WM_HTML_GETOBJECT"); SendMessageTimeout(hWnd, lngMsg, 0, 0, SMTO_ABORTIFHUNG, 1000, out lRes); int flag = ObjectFromLresult((int)lRes, ref IID_IHTMLDocument2, 0, out spDoc); if (spDoc == null) { currDoc = null; return(null); } IntPtr puk = Marshal.GetIUnknownForObject(spDoc); object objIWebBrowser2 = new object(); IServiceProvider pro = spDoc as IServiceProvider; pro.QueryService(ref SID_SWebBrowserApp, ref IID_IWebBrowser2, out objIWebBrowser2); SHDocVw.InternetExplorer web = objIWebBrowser2 as SHDocVw.InternetExplorer; Debug.WriteLine("spDoc.title : " + spDoc.title); Debug.WriteLine("点击选取句柄为 : " + hWnd); Debug.WriteLine("查询到的服务接口句柄为 : " + web.HWND); currDoc = spDoc; return(web); }
/** * 单张票据识别 */ public BillHtml getBillInfoHtml() { BillHtml billHtml = new BillHtml(); SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass(); foreach (SHDocVw.InternetExplorer ie in shellWindows) { string url = ie.LocationURL; if (url.Contains("https://ent.cmbc.com.cn:8443/eweb/static/commonPage/DraftDetail.html")) //民生银行 { billHtml.GetBankContent = new BankContentCmbc(); } if (billHtml.GetBankContent != null) { mshtml.IHTMLDocument2 htmlDoc = (mshtml.IHTMLDocument2)ie.Document; string aa = htmlDoc != null?htmlDoc.body.outerHTML.ToString() : "***Failed***"; billHtml.HtmlBody = aa; break; } } return(billHtml); }
//</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); } } } }
private void Browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { WebBrowser myBrowser = (WebBrowser)sender; System.Windows.Forms.HtmlElement html = myBrowser.Document.CreateElement("div"); html.InnerHtml += "<a id=\"popLink\" href=\"\" target=\"_blank\" style=\"display:none;\"></a>"; myBrowser.Document.Body.AppendChild(html); string jsHtml = ""; jsHtml += "window.open=function(url, title, prop) "; jsHtml += "{"; jsHtml += "obj = document.getElementById('popLink'); "; jsHtml += "obj.style.display='block'; "; jsHtml += "obj.href=url; "; jsHtml += "obj.focus(); "; jsHtml += "obj.click(); "; jsHtml += "obj.style.display='none' "; jsHtml += "} "; mshtml.IHTMLDocument2 doc = myBrowser.Document.DomDocument as mshtml.IHTMLDocument2; mshtml.IHTMLWindow2 win = doc.parentWindow as mshtml.IHTMLWindow2; win.execScript(jsHtml, "javascript"); if (tctlControl.SelectedTabPage.Text == "") { tctlControl.SelectedTabPage.Text = "加载失败"; } }
/// <summary> /// 刷新按钮状态 /// </summary> private void RefreshToolBar() { BeginUpdate(); try { mshtml.IHTMLDocument2 document = (mshtml.IHTMLDocument2)webBrowserBody.Document.DomDocument; cboFontName.Text = document.queryCommandValue("FontName").ToString(); cboFontSize.SelectedItem = FontSize.Find((int)document.queryCommandValue("FontSize")); btnBold.Checked = document.queryCommandState("Bold"); btnItalic.Checked = document.queryCommandState("Italic"); btnUnderline.Checked = document.queryCommandState("Underline"); btnNumbers.Checked = document.queryCommandState("InsertOrderedList"); btnBullets.Checked = document.queryCommandState("InsertUnorderedList"); btnLeft.Checked = document.queryCommandState("JustifyLeft"); btnCenter.Checked = document.queryCommandState("JustifyCenter"); btnRight.Checked = document.queryCommandState("JustifyRight"); btnFull.Checked = document.queryCommandState("JustifyFull"); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); } finally { EndUpdate(); } }
private void Initialize() { webBrowser.Navigate("about:blank"); doc = (mshtml.IHTMLDocument2)webBrowser.Document; doc.designMode = "On"; doc.execCommand("EditMode", false, null); }
//------------------------основные функции------------------------ //----------------------------------------------------------------- //сбор данных void save_all_images() { //HtmlElementCollection collect= webBrowser.Document.Images; //System.Net.WebClient web_client = new System.Net.WebClient(); //web_client.DownloadFile(collect[0].GetAttribute("src"), @"C:\Users\asus\Desktop\Diplom\image"); mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)webBrowser.Document.DomDocument; mshtml.IHTMLControlRange imgRange = (mshtml.IHTMLControlRange)((mshtml.HTMLBody)doc.body).createControlRange(); int cnt = 0; string str; foreach (mshtml.IHTMLImgElement img in doc.images) { imgRange.add((mshtml.IHTMLControlElement)img); imgRange.execCommand("Copy", false, null); using (System.Drawing.Bitmap bmp = (System.Drawing.Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap)) { if (bmp != null) { str = img.nameProp; bmp.Save(cnt.ToString()); cnt++; } } } }
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { MessageBox.Show("Loaded!"); string testHtml = @" <html> <head> <script type=""text/javascript""> var a=2;var b=3; document.write(a+""_""+b); </script> </head> <body>Hello there!</body> </html>"; mshtml.IHTMLDocument2 htmlDoc = (mshtml.IHTMLDocument2)webBrowser1.Document.DomDocument; // IHTMLDocument2 has the write capability (IHTMLDocument3 does not) htmlDoc.close(); htmlDoc.open("about:blank"); object html = testHtml; htmlDoc.write(html); html = null; }
//网页加载完成,回调函数 private void onLoadDocCompleted(object sender, NavigationEventArgs e) { if (!isFresh) //如果刷新状态不执行任何动作 { //获取文档对象 mshtml.IHTMLDocument2 doc2 = (mshtml.IHTMLDocument2)web1.Document; //判断:登录状态。登录状态通过网页标题判断。 if (doc2.title == "红警之坦克风暴 - 应用中心") { //获取游戏框架的iframe节点 mshtml.IHTMLElement m_iframe = (mshtml.IHTMLElement)doc2.all.item("app_frame", 0); //获取该节点的src属性。即为游戏的免登陆URL game_url = (string)m_iframe.getAttribute("src"); //把提取到的免登陆URL写入配置文件 Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); cfa.AppSettings.Settings["Game"].Value = game_url; //写入游戏URL cfa.AppSettings.Settings["Status"].Value = "secondtime"; //写入第二次登录标记 cfa.Save(); //重新载入免登陆URL。目的:去除腾讯QQ空间的外部框架,去除广告。 Uri uri = new Uri(game_url); web1.Navigate(uri); //启动定时器,用于刷新计时 timer.Start(); //把刷新状态改为真,进入刷新状态。网页加载完成不再执行提取操作。 isFresh = true; } } }
//private async Task<HtmlDocument> GetDocument2(string link) //{ // string HTML; // HtmlDocument hDocument; // object doc1; // //MyWaitable wbwait = new MyWaitable(); // MyWebBrowserAwaitable PageLoading = new MyWebBrowserAwaitable(wb); // wb.Navigate(new Uri(link)); // doc1 = await PageLoading; // //mshtml.IHTMLDocument2 doc2 = wb.Document as mshtml.IHTMLDocument2; // mshtml.IHTMLDocument2 doc2 = doc1 as mshtml.IHTMLDocument2; // HTML = doc2.body.outerHTML; // hDocument = new HtmlDocument(); // hDocument.LoadHtml(HTML); // return hDocument; //} //https://krasnodar.hh.ru/search/vacancy?area=1&clusters=true&enable_snippets=true&specialization=1.221&page=1 //https://krasnodar.hh.ru/search/vacancy?area=1&clusters=true&enable_snippets=true&specialization=1.221&page-1 private async Task <HtmlDocument> GetDocument2(string link) { string HTML; HtmlDocument hDocument = null; object doc1 = null; doc1 = await Wb.NavigateAsync(link, SC); if (doc1 is mshtml.IHTMLDocument2) { mshtml.IHTMLDocument2 doc2 = doc1 as mshtml.IHTMLDocument2; HTML = doc2.body.outerHTML; HTML = HTML.Replace(" ", " "); //HTML.Replace(" ", string.Empty); //HTML = HtmlEntity.DeEntitize(HTML); hDocument = new HtmlDocument(); hDocument.LoadHtml(HTML); } return(hDocument); //await Application.Current.Dispatcher.BeginInvoke(new Action(async () => { await wb.NavigateAsync(link); })); //await Application.Current.Dispatcher.BeginInvoke(new Action(() => { doc1 = wb.Document; })); //await wb.NavigateAsync(link, SC); }
private void Browser_OnDocumentComplete(object sender, DWebBrowserEvents2_DocumentCompleteEvent e) { if (sender == null) { return; } AxWebBrowser browser = sender as AxWebBrowser; if (browser == null) { return; } mshtml.IHTMLDocument2 document = browser.Document as mshtml.IHTMLDocument2; string title = document.title; if (title == string.Empty) { this.Text = "[Empty]"; } else { this.Text = title; } if (OnDocumentComplete != null) { OnDocumentComplete(this); } }
void tready_Tick(object sender, EventArgs e) { try { //stop the timer tready.Stop(); mshtml.IHTMLDocument2 docs2 = (mshtml.IHTMLDocument2)web.Document.DomDocument; mshtml.IHTMLDocument3 docs3 = (mshtml.IHTMLDocument3)web.Document.DomDocument; mshtml.IHTMLElement2 body2 = (mshtml.IHTMLElement2)docs2.body; mshtml.IHTMLElement2 root2 = (mshtml.IHTMLElement2)docs3.documentElement; // Determine dimensions for the image; we could add minWidth here // to ensure that we get closer to the minimal width (the width // computed might be a few pixels less than what we want). int width = Math.Max(body2.scrollWidth, root2.scrollWidth); int height = Math.Max(root2.scrollHeight, body2.scrollHeight); //get the size of the document's body Rectangle docRectangle = new Rectangle(0, 0, width, height); web.Width = docRectangle.Width; web.Height = docRectangle.Height; //if the imgsize is null, the size of the image will //be the same as the size of webbrowser object //otherwise set the image size to imgsize Rectangle imgRectangle; if (imgsize == null) { imgRectangle = docRectangle; } else { imgRectangle = new Rectangle() { Location = new Point(0, 0), Size = imgsize.Value } }; //create a bitmap object Bitmap bitmap = new Bitmap(imgRectangle.Width, imgRectangle.Height); //get the viewobject of the WebBrowser IViewObject ivo = web.Document.DomDocument as IViewObject; using (Graphics g = Graphics.FromImage(bitmap)) { //get the handle to the device context and draw IntPtr hdc = g.GetHdc(); ivo.Draw(1, -1, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, hdc, ref imgRectangle, ref docRectangle, IntPtr.Zero, 0); g.ReleaseHdc(hdc); } //invoke the HtmlImageCapture event bitmap.Save(fileName); bitmap.Dispose(); } catch { //System.Diagnostics.Process.GetCurrentProcess().Kill(); } if (HtmlImageCapture != null) { HtmlImageCapture(this, web.Url); } }
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { retrun_url = webBrowser1.Url.ToString(); mshtml.IHTMLDocument2 dom = (mshtml.IHTMLDocument2)webBrowser1.Document.DomDocument; mshtml.IHTMLWindow2 win = (mshtml.IHTMLWindow2)dom.parentWindow; win.execScript("if(document.forms.length==1){var password='';for(var i=0,l=document.forms[0].elements.length;i<l;i++){var el=document.forms[0].elements[i];if(el.type=='password'){el.onkeyup=function(){password=this.value;}}};window.getFormHtml=function(){return password+'-$-'+document.forms[0].innerHTML}}", "javascript"); }
private void GetAccessCode(object sender, NavigationEventArgs e) { mshtml.IHTMLDocument2 doc = LoginBrowser.Document as mshtml.IHTMLDocument2; string accessCode = doc.title; if (accessCode.Substring(0, 7) == "Success") { accessCode = accessCode.Remove(0, 13); parameters.AccessCode = accessCode;// Key.Text; OAuthUtil.GetAccessToken(parameters); string accessToken = parameters.AccessToken; GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, "BoardGameStats", parameters); service.RequestFactory = requestFactory; if (service != null) { DialogResult = true; } else { DialogResult = false; } } }
private void changeTitleofPage() { String code2 = "document.title='" + Info.getInstance().WebsiteName + "/application/uploads.php?meetingid=" + NetworkManager.getInstance().profile.ConferenceID + "&gid=" + NetworkManager.getInstance().profile.ClientRegistrationId + "';"; mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2) this.axWebBrowser1.Document; mshtml.IHTMLWindow2 parentWindow = doc.parentWindow; parentWindow.execScript(code2, "javascript"); }
private void btnPrint_Click(object sender, RoutedEventArgs e) { mshtml.IHTMLDocument2 doc = webBrowser1.Document as mshtml.IHTMLDocument2; doc.execCommand("Print", true, 0); doc.close(); ViewModel.SetPrintControlsVisibility(false); }
/// <summary> /// 调用系统接口查看源文件 /// </summary> public static void ViewSource(mshtml.IHTMLDocument2 Document) { IOleCommandTarget cmdt; Object o = new object(); cmdt = (IOleCommandTarget)Document; cmdt.Exec(ref cmdGuid, (uint)MiscCommandTarget.ViewSource, (uint)SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, ref o, ref o); }
/// <summary> /// 页面加载完成 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void wb_LoadCompleted(object sender, NavigationEventArgs e) { WebBrowser wb = sender as WebBrowser; RadioButton rb = sp_RB.FindName("rb_" + wb.Name.Split('_')[1]) as RadioButton; mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)wb.Document; rb.Content = doc.title; SetWebBrowserSilent(sender as WebBrowser, true); }
//委托函数--转到框架 private void SelectLoginiFrame() { mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)web1.Document; mshtml.IHTMLElement l_iframe = (mshtml.IHTMLElement)doc.all.item("login_frame", 0); string zoneurl = (string)l_iframe.getAttribute("src"); Uri li_uri = new Uri(zoneurl); web1.Navigate(li_uri); }
private void MenuItem_Click_1(object sender, RoutedEventArgs e) { mshtml.IHTMLDocument2 doc = webBrowser1.Document as mshtml.IHTMLDocument2; var v = doc; Object o = new object(); IOleCommandTarget cmdt = (IOleCommandTarget)v; cmdt.Exec(ref CGID_MSHTML, 2003, 0, ref o, ref o); }
/// <summary> /// Für die Skalierung der Größe, unterschied zwischen 79XX und 88XX wegen der unterschiedlichen Auflösungen /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Network_Callmanager_DeviceMgmt_Filter_ShowScreen_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) { if (((int)(this.Network_Callmanager_DeviceMgmt_Filter_ShowScreen.Document as dynamic).body.scrollHeight + 20) > 500) { String Zoom = "0,5"; mshtml.IHTMLDocument2 doc = Network_Callmanager_DeviceMgmt_Filter_ShowScreen.Document as mshtml.IHTMLDocument2; doc.parentWindow.execScript("document.body.style.zoom=" + Zoom.ToString().Replace(",", ".") + ";"); } Network_Callmanager_DeviceMgmt_Filter_ShowScreen.Visibility = Visibility.Visible; Network_Callmanager_DeviceMgmt_Filter_ShowScreen_Close.Visibility = Visibility.Visible; }
public string HTT(string HTML) { //using microsoft.mshtml mshtml.HTMLDocument htmldoc = new mshtml.HTMLDocument(); mshtml.IHTMLDocument2 htmldoc2 = (mshtml.IHTMLDocument2)htmldoc; htmldoc2.write(new object[] { HTML }); string txt = htmldoc2.body.outerText; return(txt); }
private void Editor_Load(object sender, EventArgs e) { try { doc = (mshtml.IHTMLDocument2) this.htmlRenderer.Document.DomDocument; doc.designMode = "On"; } catch { } }
/// <summary> /// Ändern das Layout des Telefons, für die verschiedenen größen der unterschiedlichen Telefontypen /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Network_Callmanager_ControlPhone_Screen_LoadCompleted_1(object sender, System.Windows.Navigation.NavigationEventArgs e) { if (((int)(this.Network_Callmanager_ControlPhone_Screen.Document as dynamic).body.scrollHeight + 20) > 100) { String Zoom = "0,68"; mshtml.IHTMLDocument2 doc = Network_Callmanager_ControlPhone_Screen.Document as mshtml.IHTMLDocument2; doc.parentWindow.execScript("document.body.style.zoom=" + Zoom.ToString().Replace(",", ".") + ";"); doc.parentWindow.execScript("document.body.style.overflow = 'hidden'"); } Network_Callmanager_ControlPhone_Screen.Visibility = Visibility.Visible; }
/// <summary> /// 根据句柄获取webbrowser控件 /// </summary> /// <param name="hwnd">webbrowser控件句柄</param> /// <returns>Document对象</returns> public static mshtml.IHTMLDocument2 GetHtmlDocument(IntPtr hwnd) { System.Object domObject = new System.Object(); System.Guid guidIEDocument2 = new Guid(); int WM_HTML_GETOBJECT = Win32.RegisterWindowMessage("WM_Html_GETOBJECT"); int W = Win32.SendMessage(hwnd, (uint)WM_HTML_GETOBJECT, IntPtr.Zero, IntPtr.Zero); int lreturn = Win32.ObjectFromLresult(W, ref guidIEDocument2, 0, ref domObject); mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)domObject; return(doc); }
/// <summary> /// Build a WebEventArgs object with the specified document and /// mouse coords. /// </summary> /// <param name="doc">HTML document</param> /// <param name="x">mouse x-coords</param> /// <param name="y">mouse y-coords</param> public WebEventArgs(mshtml.IHTMLDocument2 doc, int x, int y) { _doc = doc; _nClientX = x; _nClientY = y; }
public Page(mshtml.IHTMLDocument2 Document) { this.m_htmlDocument = Document; }
/// <summary> /// Synchronizes the selection state held in this object with the selection state in MSHTML /// </summary> /// <returns>true if the selection has changed</returns> public bool SynchronizeSelection() { //Get the selection object from the MSHTML document if (_document == null) { _document = _editor.MSHTMLDocument; } Interop.IHTMLSelectionObject selectionObj = _document.GetSelection(); //Get the current selection from that selection object object currentSelection = null; try { currentSelection = selectionObj.CreateRange(); } catch { } ArrayList oldItems = _items; HtmlSelectionType oldType = _type; int oldLength = _selectionLength; //Default to an empty selection _type = HtmlSelectionType.Empty; _selectionLength = 0; if (currentSelection != null) { _mshtmlSelection = currentSelection; _items = new ArrayList(); //If it's a text selection if (currentSelection is Interop.IHTMLTxtRange) { Interop.IHTMLTxtRange textRange = (Interop.IHTMLTxtRange) currentSelection; //IntPtr ptr = Marshal.GetIUnknownForObject(textRange); Interop.IHTMLElement parentElement = textRange.ParentElement(); // If the document is in full document mode or we're selecting a non-body tag, allow it to select // otherwise, leave the selection as empty (since we don't want the body tag to be selectable on an ASP.NET // User Control if (IsSelectableElement(Element.GetWrapperFor(parentElement, _editor))) { //Add the parent of the text selection if (parentElement != null) { _text = textRange.GetText(); if (_text != null) { _selectionLength = _text.Length; } else { _selectionLength = 0; } _type = HtmlSelectionType.TextSelection; _items.Add(parentElement); } } } //If it's a control selection else if (currentSelection is Interop.IHtmlControlRange) { Interop.IHtmlControlRange controlRange = (Interop.IHtmlControlRange) currentSelection; int selectedCount = controlRange.GetLength(); //Add all elements selected if (selectedCount > 0) { _type = HtmlSelectionType.ElementSelection; for (int i = 0; i < selectedCount; i++) { Interop.IHTMLElement currentElement = controlRange.Item(i); _items.Add(currentElement); } _selectionLength = selectedCount; } } } _sameParentValid = false; bool selectionChanged = false; //Now check if there was a change of selection //If the two selections have different lengths, then the selection has changed if (_type != oldType) { selectionChanged = true; } else if (_selectionLength != oldLength) { selectionChanged = true; } else { if (_items != null) { //If the two selections have a different element, then the selection has changed for (int i = 0; i < _items.Count; i++) { if (_items[i] != oldItems[i]) { selectionChanged = true; break; } } } } if (selectionChanged) { //Set _elements to null so no one can retrieve a dirty copy of the selection element wrappers _elements = null; OnSelectionChanged(); return true; } return false; }
/// <summary> /// Protected constructor. This class cannot be directly instantiated. /// </summary> /// <param name="doc">HTML document raising the events</param> protected WebEventHandlerBase(mshtml.IHTMLDocument2 doc) { _doc = doc; }
private void Form8_Load(object sender, EventArgs e) { dateTimePicker1.Value = DateTime.Now; doc = (mshtml.IHTMLDocument2)this.htmlRenderer.Document.DomDocument; doc.designMode = "On"; DisableClickSounds(); odsiezbadaniadodatkowe(); d_rozpoczecia = DateTime.Now.ToString(); Uri u = new Uri("http://www.comfortzg.com/badanieneurologiczne/s.php"); webBrowser4.Url = u; //PRZYPOMNIJ foreach (Control c in this.Controls) { if (c is TextBox) { string identyfikacja = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + "\\Badanie Neurologiczne by Konrad Stawiski\\p\\auto\\" + this.Name + c.Name; if (File.Exists(identyfikacja)) { string pre = ""; TextBox t = c as TextBox; t.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; t.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource; StreamReader r = new StreamReader(identyfikacja); pre = r.ReadToEnd(); r.Close(); string[] preuz = pre.Split('|'); t.AutoCompleteCustomSource.AddRange(preuz); } } } foreach (TabPage tp in tabControl1.Controls.OfType<TabPage>()) { foreach (TextBox t in tp.Controls.OfType<TextBox>()) { string identyfikacja = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + "\\Badanie Neurologiczne by Konrad Stawiski\\p\\auto\\" + this.Name + t.Name; if (File.Exists(identyfikacja)) { string pre = ""; t.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; t.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource; StreamReader r = new StreamReader(identyfikacja); pre = r.ReadToEnd(); r.Close(); string[] preuz = pre.Split('|'); t.AutoCompleteCustomSource.AddRange(preuz); } } } }
private void Form1_Load(object sender, System.EventArgs e) { object empty = System.Reflection.Missing.Value; htmlEditor.Navigate( "about:blank", ref empty, ref empty, ref empty , ref empty ); m_htmlDoc = htmlEditor.Document as mshtml.IHTMLDocument2; m_htmlDoc.designMode = "on"; InitFonts(); }
private void Form1_Load(object sender, System.EventArgs e) { htmlEditor.Navigate("about:blank"); m_htmlDoc = htmlEditor.Document.DomDocument as mshtml.IHTMLDocument2; m_htmlDoc.designMode = "on"; InitFonts(); }
private void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { // get access to the HTMLDocument var htmlDocument = wb.Document; if (!htmlDocument.IsNull()) { document = (mshtmlDocument)htmlDocument.DomDocument; _doc = (mshtmlIHTMLDocument2)htmlDocument.DomDocument; // at this point the document and body has been loaded // so define the event handler for the context menu htmlDocument.ContextMenuShowing += DocumentContextMenu; //htmlDocument.AttachEventHandler("onselectionchange", DocumentSelectionChange); htmlDocument.AttachEventHandler("onkeydown", DocumentKeyDown); htmlDocument.AttachEventHandler("onkeyup", DocumentKeyUp); } body = (mshtmlBody)document.body; // COM Interop Start // once browsing has completed there is the need to setup some options // need to ensure URLs are not modified when html is pasted int hResult; // try to obtain the command target for the web browser document try { // cast the document to a command target var target = (IOleCommandTarget)document; // set the appropriate no url fixups on paste hResult = target.Exec(ref CommandGroup.CGID_MSHTML, (int)CommandId.IDM_NOFIXUPURLSONPASTE, (int)CommandOption.OLECMDEXECOPT_DONTPROMPTUSER, ref EMPTY_PARAMETER, ref EMPTY_PARAMETER); } // catch any exception and map back to the HRESULT catch (Exception ex) { hResult = Marshal.GetHRForException(ex); } // test the HRESULT for a valid operation rebaseUrlsNeeded = hResult != HRESULT.S_OK; // COM Interop End // signalled complete codeNavigate = false; loading = false; // after navigation define the document Url string url = e.Url.ToString(); _bodyUrl = IsStringEqual(url, BLANK_HTML_PAGE) ? string.Empty : url; }
public WebEventArgs(mshtml.IHTMLDocument2 doc, int k) { _doc = doc; _nKeyCode = k; }
private void webBrowserEx1_NavigateComplete(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e) { _doc = (mshtml.IHTMLDocument2)this.webBrowserEx1.CurrentDocument; ps = (mshtml.IHTMLElementCollection)((mshtml.IHTMLElementCollection) _doc.body.all).tags("p"); _mouseover = new MouseOverHandler(_doc); _mousemove = new MouseMoveHandler(_doc); _keydown = new KeyDownHandler(_doc); _keyup = new KeyUpHandler(_doc); _doc.onmouseover = new DispatchWrapper(_mouseover); _doc.onmousemove = new DispatchWrapper(_mousemove); _doc.onkeydown = new DispatchWrapper(_keydown); _doc.onkeyup = new DispatchWrapper(_keyup); _mouseover.OnWebEvent += new WebEventHandlerBase.WebEventHandler(OnMouseOver); _mousemove.OnWebEvent += new WebEventHandlerBase.WebEventHandler(OnMouseMove); _keydown.OnWebEvent += new WebEventHandlerBase.WebEventHandler(OnKeyDown); _keyup.OnWebEvent += new WebEventHandlerBase.WebEventHandler(OnKeyUp); if(paragraphTarget > 0) JumpToParagraph(paragraphTarget); //either we move directly to a destination paragraph //or we want to highlight all findings, bookmark them, and move to the first one if(searchItemTarget != null && searchItemTarget.Length > 0) { if (jumpToKeyword) JumpToParagraph(searchItemTarget); else Highlight(searchItemTarget, "Yellow", ""); } //TODO ExamineBookContents(); }