简体   繁体   English

如何在C#中访问Web浏览器控件的滚动条?

[英]How to access the scrollbar of a webbrowser control in c#?

My webbrowser control has to be disabled (enabled = false) so that the user can't click in it. 我的Web浏览器控件必须被禁用(enabled = false),以便用户无法单击它。 This also disables the access to the scrollbar so I'm thinking about creating another scrollbar next to the control that gets and passes its values from and to the webbrowser's scrollbar. 这也会禁用对滚动条的访问,因此我正在考虑在控件旁边创建另一个滚动条,该控件从Web浏览器的滚动条获取和传递其值。 For that, I need to access the webbrowser scrollbar control. 为此,我需要访问webbrowser滚动条控件。 How can I find it ? 我如何找到它? webbrowser.Controls.Count returns zero. webbrowser.Controls.Count返回零。

Hmm I don't know if there is any method to acccess the scrollbar position programmaticly. 嗯,我不知道是否有任何方法可以通过编程方式获取滚动条的位置。 You can however, scroll by element name: 但是,您可以按元素名称滚动:

        private void ScrollToElement(String elemName)
    {
        if (webBrowser1.Document != null)
        {
            HtmlDocument doc = webBrowser1.Document;
            HtmlElementCollection elems = doc.All.GetElementsByName(elemName);
            if (elems != null && elems.Count > 0) 
            {
                HtmlElement elem = elems[0];

                elem.ScrollIntoView(true);
            }
        }
    }

Also, see this question for other possibilities. 另外,请参阅问题以了解其他可能性。

EDIT: 编辑:

See question Scrolling WebBrowser programatically sometimes doesn't work 请参阅问题,以编程方式滚动WebBrowser有时不起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM