你怎么prevent从刷新其显示一个RichTextBox? [英] How do you prevent a RichTextBox from refreshing its display?

查看:359
本文介绍了你怎么prevent从刷新其显示一个RichTextBox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个RichTextBox,我需要经常更新的Text属性,但是当我这样做RichTextBox的闪烁烦人,因为它刷新所有整个方法调用。

I have a RichTextBox where I need to update the Text property frequently, but when I do so the RichTextBox "blinks" annoyingly as it refreshes all throughout a method call.

我希望能找到一个简单的方法来暂时燮preSS屏幕刷新,直到我的方法做,但我已经在网络上发现的唯一的事情就是重写WndProc方法。我已经使用这种方法,但有一定的难度和副作用,它使得调试更难了。这似乎只是存在一定是这样做的更好的方法。可有人点我到一个更好的解决方案?

I was hoping to find an easy way to temporarily suppress the screen refresh until my method is done, but the only thing I've found on the web is to override the WndProc method. I've employed this approach, but with some difficulty and side effects, and it makes debugging harder, too. It just seems like there's got to be a better way of doing this. Can someone point me to a better solution?

推荐答案

我问了原来的问题,以及与WM_SETREDRAW工作最适合我的是BoltBait的使用SendMessage函数()答案。它似乎有副作用比使用WndProc方法的少了,在我的应用快两倍LockWindowUpdate执行。

I asked the original question, and the answer that worked best for me was BoltBait's use of SendMessage() with WM_SETREDRAW. It seems to have fewer side effects than the use of the WndProc method, and in my application performs twice as fast as LockWindowUpdate.

在我的扩展RichTextBox的课,我只是说这两种方法,我给他们打电话,每当我需要停下来,而我做了一些处理重启重新粉刷。如果我想从RichTextBox类以外的做到这一点,我认为它会被刚刚与参考您的RichTextBox的实例替换本工作。

Within my extended RichTextBox class, I just added these two methods, and I call them whenever I need to stop restart repainting while I'm doing some processing. If I were wanting to do this from outside of the RichTextBox class, I think it would work by just replacing "this" with the reference to your RichTextBox instance.

    private void StopRepaint()
    {
        // Stop redrawing:
        SendMessage(this.Handle, WM_SETREDRAW, 0, IntPtr.Zero);
        // Stop sending of events:
        eventMask = SendMessage(this.Handle, EM_GETEVENTMASK, 0, IntPtr.Zero);
    }

    private void StartRepaint()
    {
        // turn on events
        SendMessage(this.Handle, EM_SETEVENTMASK, 0, eventMask);
        // turn on redrawing
        SendMessage(this.Handle, WM_SETREDRAW, 1, IntPtr.Zero);
        // this forces a repaint, which for some reason is necessary in some cases.
        this.Invalidate();
    }

这篇关于你怎么prevent从刷新其显示一个RichTextBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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