本文介绍了PaintEventArgs.ClipRectangle和PaintEventArgs.Graphics.ClipBounds有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在System.Windows.Forms.Control的继承者中重写OnPaint或OnPaintBackground方法时,一个参数始终是System.Windows.Forms.PaintEventArgs对象.部分对象结构:

When overriding an OnPaint or OnPaintBackground method in an inheritor of System.Windows.Forms.Control, one argument is always a System.Windows.Forms.PaintEventArgs object. The partial object structure:

  • PaintEventArgs
    • ClipRectangle (System.Drawing.Rectangle)
    • 图形(System.Drawing.Graphics)
      • 剪辑(System.Drawing.Region)
      • ClipBounds (System.Drawing.RectangleF)
      • VisibleClipBounds (System.Drawing.RectangleF)

      Graphics.Clip 似乎是适用像素的1位图,可影响后续的绘制操作.

      Graphics.Clip appears to be a 1-bit map of applicable pixels to influence in subsequent paint operations.

      Graphics.ClipBounds 是一个只读矩形,似乎是完全包含Clip区域的最小矩形.

      Graphics.ClipBounds is a read only rectangle that appears to be the minimum rectangle to fully contain the Clip region.

      Graphics.VisibleClipBounds 似乎是一个更智能"的剪辑,尽管我无法理解它的工作方式.

      Graphics.VisibleClipBounds seems to be a more 'intelligent' clip, though I cannot understand how it operates.

      ClipRectangle 似乎在所有情况下都复制了Graphics.ClipBounds属性.

      ClipRectangle appears to in all cases duplicate the Graphics.ClipBounds property.

      有人可以回答主要问题,并可能阐明所有各种边界物体是做什么的吗?

      Can someone please answer the main question and potentially shed light on what all the various boundary objects are for?

      根据Dan-o的回答添加了MSDN的描述.

      added MSDN's descriptions as per Dan-o's answer.

      推荐答案

      PaintEventArgs.ClipRectangle是Paint事件实际上需要绘制的矩形.通常等于控件的客户区的大小.当只有一部分被另一个窗口重叠时,它将变小.或者当您调用其Invalidate(Rectangle)方法时.您可以使用它跳过绘制超出该矩形的昂贵对象.这非常罕见,Windows本身已经很好地裁剪了您绘制的内容.

      PaintEventArgs.ClipRectangle is the rectangle that actually needs to be drawn by your Paint event. Commonly equal to the size of the control's client area. It will be smaller when only a portion of it was overlapped by another window. Or when you call its Invalidate(Rectangle) method. You can use it to skip drawing expensive objects that fall outside of that rectangle. Which is pretty rare, Windows itself already does a very good job of clipping what you draw.

      Graphics.Clip是一个区域,您可以在绘图代码中为其指定以裁剪自己绘制的内容.它允许各种效果,例如绘制被圆形剪切的图像.还是使用将GraphicsPath转换为区域的复杂剪切效果.

      Graphics.Clip is a region that you can assign in your drawing code to clip what you draw yourself. It allows for various kinds of effects, like drawing an image clipped by a circle. Or really intricate clipping effects that use a GraphicsPath converted to a region.

      Graphics.ClipBounds是Graphics.Clip周围的矩形,它使数学运算更快地得到一个点是否在Graphics.Clip之外的一阶估计.如果您从未分配Clip属性(X = -4194304,Y = -4194304,Width = 8388608,Height = 8388608),您将获得无意义的无限"剪辑范围.

      Graphics.ClipBounds is the rectangle around Graphics.Clip, it makes the math faster to get a first order estimate whether or not a point is outside of Graphics.Clip. You'll get a meaningless "infinite" clip bounds if you never assigned the Clip property (X=-4194304,Y=-4194304,Width=8388608,Height=8388608)

      Graphics.VisibleClipBounds与Graphics.ClipBounds相同,但也会被控制窗口裁剪.这对于测试某个点是否在剪辑区域中对用户可见是否有用非常有用.如果您从不分配Clip属性,则只需获取窗口的大小即可.

      Graphics.VisibleClipBounds is the same as Graphics.ClipBounds but clipped also by the control window. So useful to test if a point might be inside the Clip region and visible to the user. If you never assign the Clip property then you'll just get the size of the window.

      因此是Windows来设置PaintEventArgs.ClipRectangle.其余的由您通过分配Graphics.Clip属性来设置.

      So it is Windows that sets PaintEventArgs.ClipRectangle. The rest is set by you by assigning the Graphics.Clip property.

      这篇关于PaintEventArgs.ClipRectangle和PaintEventArgs.Graphics.ClipBounds有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 05:03