Display url in text box

Creating a simple web browser in the WinForms application. In my application, I have the following components:

  • Text block
  • Web browser

Specification Requirements:

  • When you click one of the web links from WebBrowser, the URL should appear in the text box

Goal:

  • Display the URL in the address field.

Problem:

  • Not sure which event I should use? I tried to use the DocumentCompleted and VisibleChanged event in the component web browser, but this did not work.
  • How do I display a URL from a WebBrowser component in a text box?
+4
source share
3 answers
 this.Browser.DocumentTitleChanged += Browser_DocumentTitleChanged; private void Browser_DocumentTitleChanged(object sender, EventArgs e) { Uri url = ((WebBrowser)sender).Document.Url; txtUrl.Text = url.ToString(); } 

or

 this.Browser.Navigating += Browser_Navigating; private void Browser_Navigating(object sender, WebBrowserNavigatingEventArgs e) { Uri url = e.Url; txtUrl.Text = url.ToString(); } 
+4
source

You must use the Navigated event. When the event occurs, you can set the Text property to the value of the WebBrowser Url property for your text field, for example:

 addressBarTextBox.Text = webBrowser.Url.AbsoluteUri; 
+1
source

I would recommend using the WebBrowser.Navigated event. It starts as soon as the document starts loading.

Example:

 private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e) { textBox1.Text = webBrowser.Url.AbsoluteUri; } 
+1
source

Source: https://habr.com/ru/post/1337589/


All Articles