![]() You can also manipulate the contents of a Web page through the Document property, which contains an HtmlDocument object that provides managed access to the HTML document object model (DOM) for the current page. Use the DocumentText or DocumentStream property to get or set the contents of the current document as a string or data stream. The WebBrowser control also lets you display content that you create in your application or you retrieve from a database or resource file. For example, you can use the Print method to print the latest version of a Web page without displaying the page to the user. Some members are useful even when you do not want to display the WebBrowser control on your form. ![]() These and other members, such as the Stop and Refresh methods, let you implement user interface controls in your application similar to those in Internet Explorer. Navigation with any of these members causes the Navigating, Navigated, and DocumentCompleted events to occur at different stages of navigation. If the navigation is unsuccessful, a page indicating the problem is displayed. The following members let you navigate the control to a specific URL, move backward and forward through the navigation history list, and load the home page and search page of the current user: The WebBrowser control has several properties, methods, and events related to navigation. For more information, see Using Libraries from Partially Trusted Code. The WebBrowser control cannot be used by partially trusted code. You must call the Dispose() method on the same thread that attached the events, which should always be the message or user-interface (UI) thread. Be sure to call the Dispose() method when you are finished using the control to ensure that all resources are released in a timely fashion. The WebBrowser control is resource-intensive. Additionally, you can use the WebBrowser control to add your existing Web-based controls to your Windows Forms client applications. You can use the WebBrowser control, for example, to provide integrated HTML-based user assistance or Web browsing capabilities in your application. The WebBrowser control lets you host Web pages and other browser-enabled documents in your Windows Forms applications. Private Sub webBrowser1_Navigated(ByVal sender As Object, _īyVal e As WebBrowserNavigatedEventArgs) _ ![]() ' Updates the URL in TextBoxAddress upon navigation. If address.Equals("about:blank") Then Return If String.IsNullOrEmpty(address) Then Return Private Sub Navigate(ByVal address As String) ' Navigates to the given URL if it is valid. ' the ENTER key is pressed while the ToolStripTextBox has focus.īyVal sender As Object, ByVal e As KeyEventArgs) _īyVal sender As Object, ByVal e As EventArgs) _ ' Navigates to the URL in the address box when Private void webBrowser1_Navigated(object sender, If (address.Equals("about:blank")) return If (String.IsNullOrEmpty(address)) return Navigates to the given URL if it is valid. Private void goButton_Click(object sender, EventArgs e) Private void toolStripTextBox1_KeyDown(object sender, KeyEventArgs e) the ENTER key is pressed while the ToolStripTextBox has focus. Navigates to the URL in the address box when This->TextBoxAddress->Text = this->WebBrowser1->Url->ToString() Void WebBrowser1_Navigated( Object^ /*sender*/, System::Windows::Forms::WebBrowserNavigatedEventArgs^ /*e*/ ) Updates the URL in TextBoxAddress upon navigation. If ( !this->TextBoxAddress->Text->Equals( "" ) ) Void ButtonGo_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ ) Navigates to the URL in the address text box when This->WebBrowser1->Navigate( this->TextBoxAddress->Text ) If ( e->Ke圜ode = System::Windows::Forms::Keys::Enter & !this->TextBoxAddress->Text->Equals( "" ) ) Void TextBoxAddress_KeyDown( Object^ /*sender*/, System::Windows::Forms::KeyEventArgs^ e ) the ENTER key is pressed while the text box has focus. When you navigate by clicking a hyperlink, the text box automatically updates to display the current URL.įor the complete code example, see How to: Add Web Browser Capabilities to a Windows Forms Application. When you type a URL into the text box and press ENTER or click the Go button, the WebBrowser control navigates to the URL specified. This example requires that you have a form that contains a WebBrowser control called webBrowser1, a TextBox control called TextBoxAddress, and a Button control called ButtonGo. The following code example demonstrates how to implement an address bar for use with the WebBrowser control. ![]() Inherit WebBrowserBase Public Class WebBrowserĬlassInterfaceAttribute ComVisibleAttribute DockingAttribute Examples In this article public ref class WebBrowser : System::Windows::Forms::WebBrowserBase Enables the user to navigate Web pages inside your form.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |