我该如何暂停画一个控件及其子?我该、控件、其子、画一

由网友(西瓜。)分享简介:我有一个控制,我不得不做出大的修改。我想彻底prevent它重画,而我做到这一点 - SuspendLayout和ResumeLayout是不够的。我如何暂停画一个控件及其子?I have a control which I have to make large modifications to. I'd lik...

我有一个控制,我不得不做出大的修改。我想彻底prevent它重画,而我做到这一点 - SuspendLayout和ResumeLayout是不够的。我如何暂停画一个控件及其子?

I have a control which I have to make large modifications to. I'd like to completely prevent it from redrawing while I do that - SuspendLayout and ResumeLayout aren't enough. How do I suspend painting for a control and its children?

推荐答案

在我的previous工作与我们把我们的丰富的UI应用程序,以即时,顺利地油漆挣扎。我们使用标准的.NET控件,自定义控件和devex preSS控制。

At my previous job we struggled with getting our rich UI app to paint instantly and smoothly. We were using standard .Net controls, custom controls and devexpress controls.

很多使用Google和反光镜使用后我遇到了WM_SETREDRAW win32的消息。这确实停止控制绘图,而在更新它们,可以应用,这个都到母体/含面板

After a lot of googling and reflector usage I came across the WM_SETREDRAW win32 message. This really stops controls drawing whilst you update them and can be applied, IIRC to the parent/containing panel.

这是一个非常非常简单的类演示如何使用此消息:

This is a very very simple class demonstrating how to use this message:

class DrawingControl
{
    [DllImport("user32.dll")]
    public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);

    private const int WM_SETREDRAW = 11; 

    public static void SuspendDrawing( Control parent )
    {
        SendMessage(parent.Handle, WM_SETREDRAW, false, 0);
    }

    public static void ResumeDrawing( Control parent )
    {
        SendMessage(parent.Handle, WM_SETREDRAW, true, 0);
        parent.Refresh();
    }
}

有这个更全面的讨论 - 谷歌为C#和WM_SETREDRAW,如:

There are fuller discussions on this - google for C# and WM_SETREDRAW, e.g.

C#抖动

暂停布局

和向谁可能关注,这是类似的例子在VB:

And to whom it may concern, this is similar example in VB:

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Integer, _
                                                                ByVal wMsg As Integer, _
                                                                ByVal wParam As Integer,
                                                                ByVal lParam As Integer) As Integer

Private Const WM_SETREDRAW As Integer = 11

' Extension methods for Control
<Extension()>
Public Sub ResumeDrawing(ByVal Target As Control, ByVal Redraw As Boolean)
  SendMessage(Target.Handle, WM_SETREDRAW, 1, 0)
  If Redraw Then
    Target.Refresh()
  End If
End Sub

<Extension()>
Public Sub SuspendDrawing(ByVal Target As Control)
  SendMessage(Target.Handle, WM_SETREDRAW, 0, 0)
End Sub

<Extension()>
Public Sub ResumeDrawing(ByVal Target As Control)
  ResumeDrawing(Target, True)
End Sub
阅读全文

相关推荐

最新文章