Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force window to redraw?

Tags:

c#

.net

wpf

xaml

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

like image 439
user626528 Avatar asked Apr 11 '11 14:04

user626528


1 Answers

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();
like image 188
James Avatar answered Sep 22 '22 12:09

James