聚焦WebBrowser控件在C#应用程序控件、应用程序、WebBrowser

2023-09-04 00:20:36 作者:别回头他不爱你i

我有驻留在Windows中的 web浏览器控制表格。控制用于显示其在运行时获得创建超链接。这些链接指向某个HTML网页和PDF文档。

I have a WebBrowser control hosted in a windows Form. The control is used to display hyperlinks which get created at runtime. These links point to some HTML pages and PDF documents.

现在的问题是,当承载浏览器控件的形式加载,重点是在窗体上。当 TAB 键pssed,焦点不会移动到第一个超链接$ P $。不过,如果我执行一个鼠标点击控制,然后按 TAB 键,选项卡现在的重点是第一个超链接。我试图用选择() web浏览器控件,然后我叫焦点(),但它并没有解决问题。

The problem is that when the form hosting the browser control is loaded, the focus is on the form. When the TAB key is pressed, the focus does not shift to the first hyperlink. However, if I perform a mouse click on the control and then hit the TAB key, the tab focus is now on the first hyper link. I tried using Select() on the WebBrowser control and then I called Focus(), but it doesn't solve the problem.

如何设置选项卡专注于负载的第一个超链接的任何想法?谢谢你。

Any ideas on how to set the tab focus on the first hyperlink at load? Thanks.

干杯, 哈里什

推荐答案

我想这可能是因为焦点设置前的页面完全加载。试试这个:

I guess it might be because the focus is set before the page is fully loaded. Try this:

private void Go(string url)
{
    webBrowser1.Navigate(url);
    webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
}

void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    webBrowser1.Document.Body.Focus();
}

您也可以直接自动通过获取选择对焦的第一个环节上的的HtmlElement 的第一个环节。

You could also automatically select the focus on the first link directly by getting the HtmlElement of that first link.

如果上述方法不工作,你可能要检查你的code等部位,看是否别的被捕捉的焦点。尝试在$搜索选择焦点 ACTIVECONTROL C $℃。

If the above doesn't work, you might want to check other parts of your code to see if anything else is capturing the focus. Try searching for Select, Focus and ActiveControl in your code.