简体   繁体   中英

Open link in the same Visual Studio form rather than in new window (C#)

I need to automatically open a webpage via script (C#) using a Microsoft Visual Basic Form and C# Project. My script automatically opens the webpage via invoking a click event, but instead of opening in the form, the new site opens in a new web browser (Microsoft Edge) rather than a web-browser component I have placed in the Form.cs form. How can I accomplish this?

DETAILS: I am able to open a website in a web browser component in my form. There is a button on the website which I need to press to access another website. The website, however, does not open up in the same web browser component on the form - it opens up in a new window or tab in a new browser. I need to access the website this button is directing me to, but it has to be in the webbrowser component on my form.

There are two ways which allow me to access the website:

  1. By manually clicking on the button in the webbrowser component on the form
  2. By using script to click on the button: webBrowser1.Document.GetElementById("item_file_manager").InvokeMember("Click");

The reason why I want it in the same form is so I can continue to navigate to a correct, final website and upload a file to the site. I am trying to modify a site of my own and am trying to update the site with the click of a button.

Thank you for your help.

let's say you have a WebBrowser components called webBrowser1 with a TextBox associated to input URL and a button to confirm the navigation You can invoke the Navigate function which takes the Url in parameter. webBrowser1.Navigate(the url).

see the MSDN

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM