如何在处理的WinForms控制无形的画? [英] How are the painting of invisible controls handled in WinForms?

查看:201
本文介绍了如何在处理的WinForms控制无形的画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图重写的OnPaint .NET Compact Framework的

到目前为止,我能够绘制渐变的控件,圆角矩形等通常不会有可能与常规控制。

So far, I'm able to draw the controls with gradients, rounded rectangles etc that would not normally be possible with regular controls.

不过,我有问题当我要做出一个控制不可见。现在,我做的是重新绘制除了那些看不见的人所有的控制。由于需要一点时间,它会导致一些闪烁。

However, I'm having problems when I want to make a control invisible. Right now, what I do is re-draw all the controls except those invisible ones. Since it takes a bit of time, it causes some flicker.

有谁知道Windows处理如何画中的隐形控制?或者你可以建议对如何实现这一目标的任何算法或方法。

Does anyone know how windows handles painting the "invisible" controls? Or can you suggest any algorithm or method on how to achieve this.

推荐答案

有应该是你正在做的几件事情。

There should be several things you're doing.


  1. 请不要油漆权利Graphics对象传递给你的的OnPaint 。绘制到后台缓冲区,和油漆,要在年底的图形。

  2. 覆盖 OnPaintBackground ,并将它什么也不做。

  3. 无效只是改变的地区,而不是整个屏幕,尽可能保持裁剪区域小

  1. Don't paint right to the Graphics object handed to you in OnPaint. Draw to a back buffer, and paint that to the Graphics at the end.
  2. Override OnPaintBackground and have it do nothing.
  3. Invalidate only areas that change, not the entire screen, whenever possible to keep the clipping region small

如果您要改变单一的控制,以不可见,那么你改变它,只是无效它的边界正确。该在的OnPaint 你会做你的图纸,省略基于Visibility属性隐形控制。只有裁剪区域将得到更新。你甚至可以通过在的OnPaint 检查传入剪切区域,只有懒得做得出的逻辑得出该地区走得更远之一。这是复杂一点,虽然,通常是不需要的。

If you're changing a single control to "not visible", then you'd change it and invalidate just it's bounding rect. The in OnPaint you'd do your drawing, omitting the "invisible" control based on the Visibility property. Only the clipping region will get updated. You could even go one further by checking the incoming clipping region on OnPaint and only bothering to do draw logic draw that region. That's a bit more complex though, and often isn't required.

这篇关于如何在处理的WinForms控制无形的画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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