CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 1999
    Posts
    23

    Background not repainting

    I have written an app in c# that autoarchives our system files to a sourcesafe database. Some of these actions can take a while and the main form becomes white with no controls drawn. After the operation has completed the controls get redrawn but not the forms background. I have tried an invalidate but this does nothing. Can anyone tell me why the form goes blank in the first place and how to repaint the background.

    Thanks.

  2. #2
    Join Date
    Mar 2008
    Posts
    72

    Re: Background not repainting

    Calling Application.DoEvents is the simplest method.

  3. #3
    Join Date
    Aug 2005
    Location
    Seattle, Wa
    Posts
    179

    Re: Background not repainting

    Creating a thread for your methods that run a long time is the proper way.

  4. #4
    Join Date
    Mar 2008
    Location
    Atlanta, GA
    Posts
    49

    Re: Background not repainting

    Quote Originally Posted by crackersixx
    Creating a thread for your methods that run a long time is the proper way.
    Yep, the simplest way being using a BackgroundWorker. Very easy to use for simple threading. Just remember to wrap any UI changes in the following:

    Code:
    controlToChange.Invoke((MethodInvoker)delegate()
    {
      //controlToChange.Text = "whatever";
      // UI changes here
    });
    And the BackgroundWorker stuff itself:

    Code:
    BackgroundWorker bw = new BackgroundWorker();
    bw.DoWork += new DoWorkEventHandler(bw_DoWork);
    bw.RunWorkerAsync();
    
    void bw_DoWork(object sender, DoWorkEventArgs e)
    {
      // do stuff
    }

  5. #5
    Join Date
    Jun 1999
    Posts
    23

    Re: Background not repainting

    Thank you all for the replies.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured