方法 1
Private Sub Form_Load()
WebBrowser1.Navigate "http://www.google.com/"
Do
Thread.Sleep(100)
Loop While webBrowser1.IsBusy = True
End Sub
Private Sub Command1_Click()
WebBrowser1.Document.All("q").focus 'Set focus to the search text field
End Sub
Private Sub Command2_Click()
WebBrowser1.Document.All("btnI").focus 'Set focus to the google "I Am feeling lucky button"
End Sub
方法 2
このMSDN スレッドから VB.Net に変換しました: System.Windows.Controls.WebBrowser の問題に焦点を当てる
ActiveElement をwebBrowser.Document.ActiveElement.Focus()
テキストボックスまたはボタンに変更する必要があります。
Public Partial Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
Dim host As New WindowsFormsHost()
im webBrowser As New WebBrowser()
host.Child = webBrowser
elementHost1.Child = host
webBrowser.Navigate(New Uri("http://www.google.com"))
Me.Activated += Function() Do
Console.WriteLine(Me.ActiveControl)
If webBrowser.Document <> Nothing Then
If Me.ActiveControl = elementHost1 AndAlso webBrowser.Document.ActiveElement <> Nothing Then
webBrowser.Document.ActiveElement.Focus()
End If
End If
End Function
End Sub
End Class
方法 3
別の方法は、HTML で行うことです。たとえば、次のようになります。
OnLoad="document.myform2.mybutton.focus();">