Hi

I have written an application that runs in a window about a quarter of the size of the screen. If I have another window open on the screen at the same time and then drag that program across my application it looks like everything in my application gets wiped from the screen, once I stop moving the program acrros the screen my application redraws it's self. This does not seem to happen with any other window programs that I Have tried it with just mine. Is there anyway i can stop this from happening as it does not look very good :(

thanks

Simon

Dani AI

Generated

This is a classic Windows Forms repaint issue: the OS invalidates the area under the dragged window and your form either takes too long to repaint or it visibly clears the background before drawing. suggested the UI thread could be busy, and says the app appears idle — both can be true, so try isolating painting work from UI responsiveness and add buffering so redraws are quick.

A reliable first step is to enable double buffering and stop explicit background erases so the control paints in one pass. Put the style setup early (constructor or OnHandleCreated) and make sure painting is fast:

Protected Overrides Sub OnHandleCreated(e As EventArgs)
    MyBase.OnHandleCreated(e)
    Me.SetStyle(ControlStyles.UserPaint Or ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer, True)
    Me.UpdateStyles()
End Sub

You can also prevent the default background clear (only if your Paint covers the whole client area):

Protected Overrides Sub OnPaintBackground(pevent As PaintEventArgs)
    ' Intentionally empty to avoid flicker; ensure OnPaint fills the background
End Sub

If your drawing is heavy, render to an off-screen bitmap on a background thread (or use BufferedGraphics) and then blit that bitmap in OnPaint — keep OnPaint itself extremely quick. Other causes: hosted native/ActiveX controls, layered windows, or transparent controls can force different OS painting behaviour.

Quick troubleshooting checklist:

  • Make a minimal repro app with just a custom OnPaint to see if the problem reproduces.
  • Monitor CPU while dragging (Task Manager) and measure OnPaint duration with a Stopwatch.
  • Use a tool like Spy++ to watch WM_PAINT/WM_ERASEBKGND if needed.
  • Move expensive calculations off the UI thread and only draw cached bitmaps in Paint.

See Microsoft docs on double buffering and painting for details: and Control.SetStyle.

Recommended Answers

All 2 Replies

What is your application doing at this time as the white screen sounds like the CPU is maxed out or the main thread is too busy to refresh the form

It shouldn't be doing anything.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.