如何强制窗口重绘?

时间:2020-11-28 07:17:22

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?

它在Win7下运行正常,但在WinXP下,当窗口全屏时,一些窗口元素不会被重绘。有没有办法强制窗口进行完全重绘和布局更新?

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

如果我用Atl-Tab切换到另一个应用程序然后再回到我的应用程序,UPD全部重新绘制正常

1 个解决方案

#1


4  

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

您可以使用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();

#1


4  

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

您可以使用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();