<tfoot id='gtlva'></tfoot>
      <bdo id='gtlva'></bdo><ul id='gtlva'></ul>

      <small id='gtlva'></small><noframes id='gtlva'>

      <i id='gtlva'><tr id='gtlva'><dt id='gtlva'><q id='gtlva'><span id='gtlva'><b id='gtlva'><form id='gtlva'><ins id='gtlva'></ins><ul id='gtlva'></ul><sub id='gtlva'></sub></form><legend id='gtlva'></legend><bdo id='gtlva'><pre id='gtlva'><center id='gtlva'></center></pre></bdo></b><th id='gtlva'></th></span></q></dt></tr></i><div id='gtlva'><tfoot id='gtlva'></tfoot><dl id='gtlva'><fieldset id='gtlva'></fieldset></dl></div>
      <legend id='gtlva'><style id='gtlva'><dir id='gtlva'><q id='gtlva'></q></dir></style></legend>

      为 Web 浏览器控件创建 OnScroll 事件处理程序

      时间:2023-09-15
        <bdo id='jcxHj'></bdo><ul id='jcxHj'></ul>

        <legend id='jcxHj'><style id='jcxHj'><dir id='jcxHj'><q id='jcxHj'></q></dir></style></legend>

              1. <small id='jcxHj'></small><noframes id='jcxHj'>

              2. <i id='jcxHj'><tr id='jcxHj'><dt id='jcxHj'><q id='jcxHj'><span id='jcxHj'><b id='jcxHj'><form id='jcxHj'><ins id='jcxHj'></ins><ul id='jcxHj'></ul><sub id='jcxHj'></sub></form><legend id='jcxHj'></legend><bdo id='jcxHj'><pre id='jcxHj'><center id='jcxHj'></center></pre></bdo></b><th id='jcxHj'></th></span></q></dt></tr></i><div id='jcxHj'><tfoot id='jcxHj'></tfoot><dl id='jcxHj'><fieldset id='jcxHj'></fieldset></dl></div>
                  <tbody id='jcxHj'></tbody>
                <tfoot id='jcxHj'></tfoot>
                本文介绍了为 Web 浏览器控件创建 OnScroll 事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                有没有人成功地将鼠标滚动事件捕获到网络浏览器组件中?

                Has any one successfully trapped the event of mouse scroll in a web browerser component?

                我想同时滚动两个网络浏览器控件.

                I have two web browser controls i would like to scroll at the same time.

                但是网络浏览器没有滚动事件.

                But there are no scroll events for web browsers.

                我想在下面创建一个类似这样的活动?有人做过或见过吗?

                 private void webCompareSQL_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
                        {
                                Document.Window.AttachEventHandler("OnScroll");            
                        }
                

                在这里我会调用我的事件并继续执行代码.

                Here i would call my event and proceed with the code.

                private void windowEvents_OnScroll()
                {
                int nPos = GetScrollPos(webCompareSQL.Handle, (int)ScrollBarType.SbVert); 
                nPos <<= 16;
                uint wParam = (uint)ScrollBarCommands.SB_THUMBPOSITION | (uint)nPos;
                SendMessage(WebPrevSQL.Handle, (int)Message.WM_VSCROLL, new IntPtr(wParam), new IntPtr(0));        
                }
                

                我找到了这段代码,但不知道如何使用它.这是一个事件.

                I have found this code but don't know how to use it. its an event.

                webCompareSQL.Document.Window.Scroll
                

                推荐答案

                我能够让这个工作如下.此示例假定两个 Web 浏览器控件都导航到同一个 Url.除了垂直滚动条之外,我还同步水平滚动条 - 如果不需要,可以省略.

                I was able to get this working as follows. This example assumes that both web browser controls are navigating to the same Url. I am also syncing the horizontal scrollbar in addition to the vertical - this can be omitted if it is not required.

                webBrowser1.DocumentCompleted
                    += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
                webBrowser2.DocumentCompleted
                    += new WebBrowserDocumentCompletedEventHandler(webBrowser2_DocumentCompleted);
                
                NavigateToPage("www.google.com");
                
                ....
                
                private void NavigateToPage(string url)
                {
                    webBrowser1.Navigate(url);
                    webBrowser2.Navigate(url);
                }
                
                private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
                {
                    webBrowser1.Document.Window.AttachEventHandler("onscroll", OnScrollEventHandler1);
                }
                
                private void webBrowser2_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
                {
                    webBrowser2.Document.Window.AttachEventHandler("onscroll", OnScrollEventHandler2);
                }
                
                public void OnScrollEventHandler1(object sender, EventArgs e)
                {           
                    webBrowser2.Document.GetElementsByTagName("HTML")[0].ScrollTop
                        = webBrowser1.Document.GetElementsByTagName("HTML")[0].ScrollTop;
                    webBrowser2.Document.GetElementsByTagName("HTML")[0].ScrollLeft
                        = webBrowser1.Document.GetElementsByTagName("HTML")[0].ScrollLeft;
                }
                
                public void OnScrollEventHandler2(object sender, EventArgs e)
                {
                    webBrowser1.Document.GetElementsByTagName("HTML")[0].ScrollTop
                        = webBrowser2.Document.GetElementsByTagName("HTML")[0].ScrollTop;
                    webBrowser1.Document.GetElementsByTagName("HTML")[0].ScrollLeft
                        = webBrowser2.Document.GetElementsByTagName("HTML")[0].ScrollLeft;
                } 
                

                我注意到您在 中的评论.NET中如何获取webbrowser控件的滚动条位置,与此操作相关

                I note your comment in How to retrieve the scrollbar position of the webbrowser control in .NET, relating to this operation

                webBrowser1.Document.GetElementsByTagName("HTML")[0].ScrollTop
                

                不工作.我可以确认这绝对适用于我的机器,因此如果此代码在您的机器上不起作用,我可以寻找替代方案.

                not working. I can confirm that this definitely works on my machine, so if this code does not work on yours I can look into alternatives.

                这篇关于为 Web 浏览器控件创建 OnScroll 事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:何时连接事件处理程序 asp.net 下一篇:如何删除所有事件处理程序

                相关文章

                <i id='x3QqW'><tr id='x3QqW'><dt id='x3QqW'><q id='x3QqW'><span id='x3QqW'><b id='x3QqW'><form id='x3QqW'><ins id='x3QqW'></ins><ul id='x3QqW'></ul><sub id='x3QqW'></sub></form><legend id='x3QqW'></legend><bdo id='x3QqW'><pre id='x3QqW'><center id='x3QqW'></center></pre></bdo></b><th id='x3QqW'></th></span></q></dt></tr></i><div id='x3QqW'><tfoot id='x3QqW'></tfoot><dl id='x3QqW'><fieldset id='x3QqW'></fieldset></dl></div>
                    <bdo id='x3QqW'></bdo><ul id='x3QqW'></ul>
                1. <small id='x3QqW'></small><noframes id='x3QqW'>

                  <legend id='x3QqW'><style id='x3QqW'><dir id='x3QqW'><q id='x3QqW'></q></dir></style></legend><tfoot id='x3QqW'></tfoot>