Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4013522
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:22:55+00:00 2026-05-20T09:22:55+00:00

I have a WinForms form with, amongst other things, a WebBrowser control. I use

  • 0

I have a WinForms form with, amongst other things, a WebBrowser control. I use the browser to display a preview of the file the user creates.

When the user loads a document, I want it to automatically refresh the preview window to show the new document. This works 100%.

However, I just added a “Load most recent document” feature which, as you should be able to tell, loads the last document on program start up. Although it goes through the same code path as any other method of loading a document (Open button, File->Open, File->MRU, etc), the preview does not refresh on start up.

I’ve followed the execution in the debugger, and all the code is being executed. However, it appears that the WebBrowser simply isn’t working. If I hit the refresh button (which goes through the same code path) afterwards, it works fine.

public partial class frmMain : Form {

    int scrolltop = 0, scrollleft = 0;

    delegate void VoidDelegate();

    private void Form1_Load(object sender, EventArgs e) {

        //irrelevant initialization code omitted

        //this is normally 'about:blank', but it doesn't matter anyway
        html.Navigate("http://google.com");

        NewFile();

        if (GlobalSettings.MRU.Files.Count > 0) {
            LoadFile(GlobalSettings.MRU.Files[0]);
        }
    }

    public void NewFile() {

        //misc blanking omitted

        html.DocumentText = "";
    }

    private void LoadFile(string file) {
        //file loading code omitted

        //Trying to call RefreshPreview after everything else is done.
        this.Invoke(new VoidDelegate(RefreshPreview));
        //RefreshPreview());
    }

    public void RefreshPreview() {
        //preserve the position if possible
        if (html.Document.Body != null) {
            scrolltop = html.Document.Body.ScrollTop;
            scrollleft = html.Document.Body.ScrollLeft;
        }

        //string code = HtmlProcessing.ProcessCode(txtCode.Text, GetImageList());
        string code = "If you can see this, it worked.";

        html.DocumentText = code;
    }
}

If you paste this code into a form named frmMain with a WebBrowser control named html, and hook up the Form1_Load event (note to self, rename this ;), you should be able to reproduce this sample. Maybe add a button that calls RefreshPreview() too.

So, short version: During Form_Load, WebBrowser doesn’t do anything. Afterwards, it works fine. I need it to do something during Form_Load, what am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:22:55+00:00Added an answer on May 20, 2026 at 9:22 am

    I would recommend moving your code to the Form.Shown event. The problem is likely due to the order and timing of Form events. Since Load occurs prior to display of the form, the WebBrowser’s VisibleChanged event never occurs, and I believe it is completely inactive.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In WinForms, I can design a form and have a TabValue to control which
I have a listview control that is on a winforms form. It fills the
I have a .NET 2.0 WinForms application with a ToolStrip on my main form.
I have a WinForms application with a DataGridView control and a column of DataGridViewButtonCell
I have a winforms application that presently ships with a chm file for context-sensitive
I have a WinForms application with a view where the user selects a single
I have a WinForms form that won't close. In OnFormClosing, e.Cancel is set to
I have a winforms form which is inherited from another form. e.g. class StartForm
I have 2 winforms Form 1 and Form 2. I have button1 in form1,
I have a form (WinForms) with a TextBox Binded to a Datasource. The datasource

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.