WebBrowser.Navigated Olay
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
WebBrowser Denetim yeni bir belgeye gidip yüklemeye başladığında gerçekleşir.
public:
event System::Windows::Forms::WebBrowserNavigatedEventHandler ^ Navigated;
public event System.Windows.Forms.WebBrowserNavigatedEventHandler Navigated;
public event System.Windows.Forms.WebBrowserNavigatedEventHandler? Navigated;
member this.Navigated : System.Windows.Forms.WebBrowserNavigatedEventHandler
Public Custom Event Navigated As WebBrowserNavigatedEventHandler
Public Event Navigated As WebBrowserNavigatedEventHandler
Olay Türü
Örnekler
Aşağıdaki kod örneği, denetim için bir adres çubuğu uygulamak üzere olay işleyicisinin NavigatedWebBrowser nasıl kullanılacağını gösterir. Bu örnek, formunuzun adlı bir denetim, adlı WebBrowserbir webBrowser1TextBox denetim ve adlı TextBoxAddressbir Button denetim içermesini ButtonGogerektirir. Metin kutusuna bir URL yazıp ENTER tuşuna bastığınızda veya Git düğmesine tıkladığınızda, WebBrowser denetim belirtilen URL'ye gider. Köprüye tıklayarak gezindiğinizde, metin kutusu geçerli URL'yi görüntüleyecek şekilde otomatik olarak güncelleştirilir.
Kod örneğinin tamamı için bkz. H nasıl yapılır: Windows Forms Uygulamasına Web Tarayıcısı Özellikleri Ekleme.
// Navigates to the URL in the address text box when
// the ENTER key is pressed while the text box has focus.
void TextBoxAddress_KeyDown( Object^ /*sender*/, System::Windows::Forms::KeyEventArgs^ e )
{
if ( e->KeyCode == System::Windows::Forms::Keys::Enter && !this->TextBoxAddress->Text->Equals( "" ) )
{
this->WebBrowser1->Navigate( this->TextBoxAddress->Text );
}
}
// Navigates to the URL in the address text box when
// the Go button is clicked.
void ButtonGo_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
if ( !this->TextBoxAddress->Text->Equals( "" ) )
{
this->WebBrowser1->Navigate( this->TextBoxAddress->Text );
}
}
// Updates the URL in TextBoxAddress upon navigation.
void WebBrowser1_Navigated( Object^ /*sender*/, System::Windows::Forms::WebBrowserNavigatedEventArgs^ /*e*/ )
{
this->TextBoxAddress->Text = this->WebBrowser1->Url->ToString();
}
// Navigates to the URL in the address box when
// the ENTER key is pressed while the ToolStripTextBox has focus.
private void toolStripTextBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
Navigate(toolStripTextBox1.Text);
}
}
// Navigates to the URL in the address box when
// the Go button is clicked.
private void goButton_Click(object sender, EventArgs e)
{
Navigate(toolStripTextBox1.Text);
}
// Navigates to the given URL if it is valid.
private void Navigate(String address)
{
if (String.IsNullOrEmpty(address)) return;
if (address.Equals("about:blank")) return;
if (!address.StartsWith("http://") &&
!address.StartsWith("https://"))
{
address = "http://" + address;
}
try
{
webBrowser1.Navigate(new Uri(address));
}
catch (System.UriFormatException)
{
return;
}
}
// Updates the URL in TextBoxAddress upon navigation.
private void webBrowser1_Navigated(object sender,
WebBrowserNavigatedEventArgs e)
{
toolStripTextBox1.Text = webBrowser1.Url.ToString();
}
' Navigates to the URL in the address box when
' the ENTER key is pressed while the ToolStripTextBox has focus.
Private Sub toolStripTextBox1_KeyDown( _
ByVal sender As Object, ByVal e As KeyEventArgs) _
Handles toolStripTextBox1.KeyDown
If (e.KeyCode = Keys.Enter) Then
Navigate(toolStripTextBox1.Text)
End If
End Sub
' Navigates to the URL in the address box when
' the Go button is clicked.
Private Sub goButton_Click( _
ByVal sender As Object, ByVal e As EventArgs) _
Handles goButton.Click
Navigate(toolStripTextBox1.Text)
End Sub
' Navigates to the given URL if it is valid.
Private Sub Navigate(ByVal address As String)
If String.IsNullOrEmpty(address) Then Return
If address.Equals("about:blank") Then Return
If Not address.StartsWith("http://") And _
Not address.StartsWith("https://") Then
address = "http://" & address
End If
Try
webBrowser1.Navigate(New Uri(address))
Catch ex As System.UriFormatException
Return
End Try
End Sub
' Updates the URL in TextBoxAddress upon navigation.
Private Sub webBrowser1_Navigated(ByVal sender As Object, _
ByVal e As WebBrowserNavigatedEventArgs) _
Handles webBrowser1.Navigated
toolStripTextBox1.Text = webBrowser1.Url.ToString()
End Sub
Açıklamalar
Denetim WebBrowser , aşağıdaki özelliklerden biri ayarlandığında veya yöntemler çağrıldığında yeni bir belgeye gider:
Navigated Denetim yeni bir belgeye gittiği zaman WebBrowser bildirim almak için olayı işleyebilirsiniz. Olay gerçekleştiğindeNavigated, yeni belge yüklenmeye başlar, yani yüklenen içeriğe , Documentve DocumentText özellikleri aracılığıyla DocumentStreamerişebilirsiniz. Denetim yeni belgeyi DocumentCompleted yüklemeyi tamamladığında WebBrowser bildirim almak için olayı işleyebilirsiniz.
Ayrıca, gezinti başlamadan önce olayı işleyerek Navigating de bildirim alabilirsiniz. Bu olayı işlemek, belirli koşullar karşılanmadıysa ( örneğin, kullanıcı formu tamamen doldurmadıysa) gezintiyi iptal etmenizi sağlar.
Olayları işleme hakkında daha fazla bilgi için bkz . Olayları İşleme ve Oluşturma.