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

  • SEARCH
  • Home
  • 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 137477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:06:44+00:00 2026-05-11T07:06:44+00:00

I’m trying to use a loading overlay on top of a Windows form that

  • 0

I’m trying to use a loading overlay on top of a Windows form that adds a 50% opaque layer on top of a windows form with a loading GIF, while it does what it needs to do in a background thread. The overlay is a windows form that I’m drawing in the onPaint event.

The loading overlay works fine on multiple different form loads, but fails to work properly when summoned to ensure patience during a 30 second upload process (That Prints a Word Document to PDF, then uploads that PDF to a SQL Server). This upload collects some data from the form, puts it into an Object, then operates entirely on a background thread. The loading overlay will appear, show the first frame loading GIF, then just freeze. The onPaint is getting fired and the image frame is being updated, but it isn’t visible

Constructor sets the form to be UserPainted:

Sub New()     InitializeComponent()     SetStyle(ControlStyles.UserPaint Or ControlStyles.Opaque, True)  End Sub 

Then, in the Form.Shown event the ImageAnimator.Animate method is called:

Private Sub LoadingOverlay_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown     If Not currentlyAnimating Then         ImageAnimator.Animate(animatedImage, AddressOf Me.OnFrameChanged)         currentlyAnimating = True     End If End Sub 

The onFrameChanged Event Handler just Invalidates the form:

Private Sub OnFrameChanged(ByVal sender As Object, ByVal e As System.EventArgs)     'Force a call to onPaint     Me.Invalidate() End Sub 

Then onPaint is overridden and does the drawing:

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)     MyBase.OnPaint(e)      'Get the next frame ready for rendering     ImageAnimator.UpdateFrames()      'Draw the next frame in the animation.     e.Graphics.DrawImage(Me.animatedImage, GetCenter(Me.animatedImage.Size))     TextRenderer.DrawText(e.Graphics, strStatus, Me.Font, GetTextLocation(Me.animatedImage.Size), Color.White, Color.Black)  End Sub 

Finally, the ImageAnimator.StopAnimate method is called in the Form Closing event:

Private Sub LoadingOverlay_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed     If currentlyAnimating Then         ImageAnimator.StopAnimate(animatedImage, AddressOf Me.OnFrameChanged)         currentlyAnimating = False     End If End Sub 

Here’s how the loading overlay is being called and closed:

Private Sub ShowLoadingOverlay()     If Not blnLoadingOverlayVisible Then          Me.Enabled = False          patience = New LoadingOverlay()         patience.Location = Point.Add(parent.PointToScreen(Me.Location), New Size(0, parent.ToolStrip.Height + parent.MenuStrip.Height))         patience.Size = Me.Size         patience.Show()         patience.BringToFront()          blnLoadingOverlayVisible = True      End If End Sub  Private Sub HideLoadingOverlay()     If blnLoadingOverlayVisible Then         'Close loading overlay'         patience.Close()         patience.Dispose()         patience = Nothing         Me.Enabled = True         blnLoadingOverlayVisible = False     End If End Sub 
  • 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. 2026-05-11T07:06:45+00:00Added an answer on May 11, 2026 at 7:06 am

    ‘some COM’ is relevant. You’ll hit COM’s apartment threading rulez. A COM object like Word must be created on an STA thread. Your main UI thread qualifies, it starts at Main() and it has the [STAThread] attribute. Any method calls you make on another thread are automatically marshaled by COM to the STA thread. Gumming up your animation.

    This isn’t easy to fix. You’d need a background thread that must be an STA thread as well, use Thread.SetApartmentState(). And pump a message loop, use Application.Run(). Getting your code started and exiting the loop is awkward, try using a form that overrides SetVisibleCore() so you can avoid making it visible.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.