聚焦WebBrowser控件在C#应用程序 [英] Focusing WebBrowser control in a C# application

查看:154
本文介绍了聚焦WebBrowser控件在C#应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有驻留在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.

这篇关于聚焦WebBrowser控件在C#应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆