user626528
user626528

Reputation: 14418

How to force window to redraw?

I have a full-screen window, using this code:

WindowStyle = System.Windows.WindowStyle.None;
WindowState = System.Windows.WindowState.Maximized;
Topmost = true;

It works ok under Win7, but under WinXP some window elements don't get redrawn when the window goes fullscreen. Is there any way to force window to make full redraw and layout update?

UPD all is redrawn ok, if I switch to another app with Atl-Tab and then back to mine

Upvotes: 6

Views: 7681

Answers (1)

James
James

Reputation: 2841

You could force the window to repaint by using the Windows API.

Example class implementation:

public static class WindowsApi
{
    private const int WmPaint = 0x000F;

    [DllImport("User32.dll")]
    public static extern Int64 SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);

    public static void ForcePaint(this Form form)
    {
        SendMessage(form.Handle, WmPaint, IntPtr.Zero, IntPtr.Zero);
    }
}

Usage:

Form testForm = new Form();
testForm.ForcePaint();

Upvotes: 6

Related Questions