简体   繁体   中英

Can you refresh a browser programmatically using c#/wpf

I've created a program that launches a wpf browser in c#. I've overloaded the exit button to hide the browser rather than close it on exit, and when the program is relaunched it's simply made visible (this why it doesn't have to reload every time). However when it's made visible again, the page resumes the spot it was exited at, so on exit I'd like to hide and refresh the page (refreshing it will bring it back to its "home" page).

The code looks something like this as of now:

protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
       e.Cancel = true;
       //do my stuff before closing
      //dll import function to hide

}

If anyone knows a function I can use to refresh the page let me know. I'm using [DllImport("User32.dll")] with FindWindow to hide the function.

Note that the page is launched through REST commands so closing it and reopening it is not an option.

You can use SendKeys to do this:

protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
    e.Cancel = true;
    //do my stuff before closing
    //dll import function to hide

    SendKeys.Send("{F5}"); //The page will refresh the browser.
}

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