Metoda 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
Metoda 2
I konwertowane go do VB.Net z tego MSDN thread: Focus issues with System.Windows.Controls.WebBrowser
trzeba będzie zmienić ActiveElement w webBrowser.Document.ActiveElement.Focus()
do pola tekstowego lub przycisku.
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
Metoda 3
Innym sposobem może być to zrobić w HTML, np:
OnLoad="document.myform2.mybutton.focus();">
Co oznacza "mój kod jest niezdolny"? Czy otrzymujesz komunikat o błędzie?Co dokładnie się dzieje? Co robi, gdy używasz debuggera z punktem przerwania w linii 'If adtxt.Text'? –
Gdzie umieszczasz ten kod? – Ryan
Nie używaj klawisza TAB, znajdę ci bardziej niezawodną metodę ustawiania fokusu na element HTLM w kontrolce WebBrowser –