创建一个控件,只要引发Paint事件,该控件将仅重新绘制指定的Region而不是所有Region? [英] Create a control which will be re-painted only a specified Region not all the Region whenever Paint event is raised?

查看:62
本文介绍了创建一个控件,只要引发Paint事件,该控件将仅重新绘制指定的Region而不是所有Region?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,每当重新绘制一个控件时,其所有客户区/区域都将被重新绘制,就像使用Invalidate()而不是Invalidate(Region)一样。



如果我自己调用Invalidate()重新绘制控件,它会正常(我将传入指定的Region以使其无效)。然而,某些我无法控制的代码可能会使控件无效(这会使所有控件无效,我不希望这种情况发生,只是某些区域需要被无效)。



我尝试重写OnInvalidated方法,但其参数(InvalidateEventArgs)只有一个名为InvalidRect的属性(Rectangle的类型,而不是Region)。我们都知道调用Invalidate()将引发控件的Paint事件(对于整个控件),调用Invalidate(Region)将引发控件的Panit事件(对于控件上的指定Region),等等我想知道Invalidate(Region)如何告诉底层的Paint事件提升机制知道正在绘制的Region ???



或者有什么东西特别在这里(与MouseUp,MouseDown,MouseMove,KeyPress等几乎其他事件相比)?



请帮我解决这个问题,或者告诉我是否这不可能。至少我想知道上面粗体问题的答案。当然,知道这个问题的答案将有助于我创建我想要的控制。 (如标题中所述)。



我们非常感谢您的帮助!谢谢!



VipHaLong

By default, whenever a control is repainted, all its client area / region will be repainted like as using Invalidate() not Invalidate(Region).

If I call Invalidate() myself to repaint the control, it will be OK (I will pass in a specified Region to make it invalidated only). However the control may be invalidated by some code that I can''t control (this will invalidate all the control and I don''t want this to happen, just some Region is in need to be invalidated).

I''ve tried overriding OnInvalidated method, but its argument (InvalidateEventArgs) has only a property called InvalidRect (type of Rectangle, not a Region). We all know that calling to Invalidate() will raise the Paint event of the control (for the whole control), calling to Invalidate(Region) will raise the Panit event of the control (for a specified Region on the control), and so I wonder how Invalidate(Region) tells the underlying Paint event raising mechanism to know the Region being painted???

Or there is something special here (compared to almost other events such as MouseUp, MouseDown, MouseMove, KeyPress,...)?

Please help me solve this problem, or tell me if that''s impossible. At least I want to know the answer to the question in bold above. Of course, knowing the answer to that question will help me create the control I want. (as mentioned in the title).

Your help would be highly appreciated! Thanks!

VipHaLong

推荐答案

它不能完全按照您的概述工作。首先,请阅读这个简短但有用的讨论: http:// stackoverflow .com / questions / 7507602 / best-practice-for-onpaint-invalidate-clipping-and-regions [ ^ ]。

这是最难的方式,但我建议你先从 PaintEventArgs.ClipRectangle [ ^ ]属性。

但是我不知道操作系统是如何优化失效的,但是您可以尝试上面的msnd页面中的示例来查看何时以及通过哪个剪切矩形。但您可以肯定使用此信息来过滤您需要重绘的内容。
It does not work exactly as you outlined. First of all, read this short but helpful discussion: http://stackoverflow.com/questions/7507602/best-practice-for-onpaint-invalidate-clipping-and-regions[^].
That is the hardest way, but I suggest you start with the PaintEventArgs.ClipRectangle[^] property.
But I don''t know how the OS is optimizing the invalidation, but you can try the sample from the above msnd page to see when and what clipping rectangle is passed. But you can for sure use this information to filter what you need to redraw.


这篇关于创建一个控件,只要引发Paint事件,该控件将仅重新绘制指定的Region而不是所有Region?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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