我可以暂停一种形式的重新划分,直到我已经完成所有更新? [英] Can I suspend redrawing of a form until I have performed all updates?

查看:126
本文介绍了我可以暂停一种形式的重新划分,直到我已经完成所有更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用C#和.NET 2.0中,我使用的是形状不规则的形式(TransparencyKey,FormBorderStyle =无,等...),并要允许正常的边界模式。

我改回颜色由石灰违约 我改变FormBorderStyle为FixedSingle 我改变TransparencyKey到Colour.None

Unfortuanately这看起来在屏幕上一塌糊涂的形象跳几个像素下来,一边和浅绿色的形式。

我想,这是由表格造成code每行之后被重新绘制,是有可能暂停绘图的形式,直到我做了我的变化,然后就重新绘制表格一次?

解决方案

新的答案:重写WndProc,虽然在应用新的窗口属性阻止WM_PAINT消息

老答案:重写WndProc,并阻断 WM_ERASEBKGND 的消息

什么样的​​code以下确实说明:

在一个窗口的区域是无效的,Windows发送一系列消息到导致新鲜油漆插件的控制。本系列的早期消息 WM_ERASEBKGND 。通常情况下,响应于该消息,控制描绘本身纯色。后来,在应对 WM_PAINT 消息(通常是由我们的OnPaint事件消耗)实际的绘制完成。如果此图是不平凡会有一段延迟后小部件更新,你会得到一个恼人的闪烁。<​​/ P>

看你的code,我再次清楚地解决不同的问题。试试这个新的例子。这将阻止窗体/控件的画,如果 bAllowPaint 标志未设置。

的例子:

 私人const int的WM_PAINT = 0x000F;

    保护覆盖无效的WndProc(参考消息M)
    {
        如果((m.Msg!= WM_PAINT)||
            (bAllowPaint&安培;&安培; m.Msg == WM_PAINT))
        {
            base.WndProc(REF米);
        }
    }
 

的例子:

 私人const int的WM_ERASEBKGND = 0x0014;

    保护覆盖无效的WndProc(参考消息M)
    {
        如果(m.Msg!= WM_ERASEBKGND)//忽略WM_ERASEBKGND
        {
            base.WndProc(REF米);
        }
    }
 

Using C# and .Net 2.0, I'm using an irregularly shaped form (TransparencyKey, FormBorderStyle = None, etc...) and want to allow "normal" bordered mode.

I change the back colour to default from Lime I change FormBorderStyle to FixedSingle I change the TransparencyKey to Colour.None

Unfortuanately this looks a complete mess on screen with the image jumping a few pixels down and to the side and Lime green form.

I think this is caused by the form being redrawn after each line of code, is it possible to suspend drawing the form until I have made my changes and then just redraw the form once?

G

解决方案

NEW answer: Override the WndProc and block the WM_PAINT message while you apply the new Window properties.

OLD answer: Override the WndProc, and block the WM_ERASEBKGND message.

Explanation of what the code below does:

When a window's region is invalidated, Windows sends a series of messages to the control that result in a freshly-painted widget. An early message in this series is WM_ERASEBKGND. Normally, in response to this message, the control paints itself a solid color. Later, in response to the WM_PAINT message (which is usually consumed by us in the OnPaint event) the actual drawing is done. If this drawing is non-trivial there will be a delay before the widget is updated and you'll get an annoying flicker.

Looking at your code again I was clearly solving a different problem. Try this new example. It will block the painting of the form/control if the bAllowPaint flag is unset.

The NEW example:

    private const int WM_PAINT = 0x000F;

    protected override void WndProc(ref Message m)
    {
        if ((m.Msg != WM_PAINT) ||
            (bAllowPaint && m.Msg == WM_PAINT))
        {
            base.WndProc(ref m);
        }
    }

The OLD example:

    private const int WM_ERASEBKGND = 0x0014;

    protected override void WndProc(ref Message m)
    {
        if (m.Msg != WM_ERASEBKGND) // ignore WM_ERASEBKGND
        {
            base.WndProc(ref m);
        }
    }

这篇关于我可以暂停一种形式的重新划分,直到我已经完成所有更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆