WinForms 绘制周期文档?
WinForms 中有关于绘制周期的文档吗?
当我在 Windows 中编程时,绘制周期通常采用以下形式:
sent a WM_PAINT message
{
call BeginPaint(&paintStruct)
//BeginPaint sends WM_NCPAINT and WM_ERASEBKGND
sent a WM_ERASEBKGND message
{
i can:
- allow default processing (Windows will fill the area with the default background color (e.g. white)
- erase and background myself (e.g. a gradient) and prevent default processing
- do nothing (letting whatever was there before me stay there) and prevent default processing
}
perform whatever painting i desire on
paintStruct.hDC (Device Context)
paintStruct.rcPaint (Invalid Rectangle)
that was populated into paintStruct during BeginPaint
call EndPaint()
}
这全部记录在 MSDN 上: Windows Development\Graphics and Multimedia\Windows GDI\Painting and Drawing\About Painting and Drawing
我找不到任何有关 WinForms 及其绘制周期的此类文档。我可以随机找到名称为paint的方法和事件:
OnPaint
(受保护方法“引发 Paint 事件”。)OnPrint
(受保护方法“引发 Paint 事件”。)- InvokePaint(受保护方法“引发 Paint 事件”指定的控件。")
画图
(公共事件)
- < code>InvokePaintBackground(受保护方法“引发指定控件的 PaintBackground 事件。”)
OnPaintBackground
(受保护的方法“绘制控件的背景。”)
注意:忽略没有
PaintBackground
事件的事实
是否有文档描述这些实体之间的设计关系? WinForms 中有关于绘制周期的文档吗?
Is there documentation on the paint cycle in WinForms?
When i am programming in Windows the paint cycle is usually of the form:
sent a WM_PAINT message
{
call BeginPaint(&paintStruct)
//BeginPaint sends WM_NCPAINT and WM_ERASEBKGND
sent a WM_ERASEBKGND message
{
i can:
- allow default processing (Windows will fill the area with the default background color (e.g. white)
- erase and background myself (e.g. a gradient) and prevent default processing
- do nothing (letting whatever was there before me stay there) and prevent default processing
}
perform whatever painting i desire on
paintStruct.hDC (Device Context)
paintStruct.rcPaint (Invalid Rectangle)
that was populated into paintStruct during BeginPaint
call EndPaint()
}
This is all documented on MSDN: Windows Development\Graphics and Multimedia\Windows GDI\Painting and Drawing\About Painting and Drawing
i cannot find any such documentation about WinForms and its paint cycle. i can randomly find methods and events that have the name paint in them:
OnPaint
(protected method "Raises the Paint event.")OnPrint
(protected method "Raises the Paint event.")- InvokePaint (protected method "Raises the Paint event for the specified control.")
Paint
(public event)InvokePaintBackground
(protected method "Raises the PaintBackground event for the specified control.")OnPaintBackground
(protected method "Paints the background of the control.")
Note: Ignoring the fact that there is no
PaintBackground
event
Is there documentation describing the design relationship between these entities? Is there documentation on the paint cycle in WinForms?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它与本机 Windows 绘制周期没有本质区别,.NET 事件由相应的 Windows 消息引发。从底部开始,消息是通过窗口管理器或应用程序本身调用 InvalidateRect() 生成的。 .NET 版本是 Control.Invalidate()。 Windows 跟踪窗口的更新区域,决定是否传递 WM_PAINT、WM_NCPAINT 和 WM_ERASEBKGND 消息。
当 ControlStyles.UserPaint 样式打开时,Control.WndProc() 可以识别 WM_PAINT 和 WM_ERASEBKGND 消息。它调用虚拟 OnPaint() 和 OnPaintBackground() 方法。派生控件可以重写这些方法以根据需要自定义绘制。并且必须调用基方法。最终到达 Control.OnPaint/Background 方法,该方法触发 Paint 和 PaintBackground 事件以允许其他代码自定义绘画。
唯一的其他问题是双缓冲,由 DoubleBuffered 属性启用。 Winforms 为控件创建一个位图缓冲区,并运行 OnPaintBackground() 和 OnPaint(),传递从该位图创建的 Graphics 对象。然后将位图传输到屏幕上。
It isn't substantially different from the native Windows paint cycle, the .NET events are raised by the corresponding Windows messages. Starting from the bottom, the messages are generated by a call to InvalidateRect(), either by the window manager or by the app itself. The .NET version is Control.Invalidate(). Windows keeps track of the update region for the window, deciding whether to deliver a WM_PAINT, WM_NCPAINT and WM_ERASEBKGND message.
The WM_PAINT and WM_ERASEBKGND messages are recognized by Control.WndProc() when the ControlStyles.UserPaint style is turned on. It calls the virtual OnPaint() and OnPaintBackground() methods. A derived control can override these methods to customize the painting as necessary. And must call the base method. Eventually that reaches the Control.OnPaint/Background method, that fires the Paint and PaintBackground events to allow other code to customize the painting.
The only other wrinkle is double-buffering, enabled by the DoubleBuffered property. Winforms creates a bitmap buffer for the control and runs OnPaintBackground() and OnPaint(), passing a Graphics object created from that bitmap. Then blits the bitmap to the screen.
这是您要找的吗?
MSDN:自定义控件绘制和渲染
OP 编辑:当微软实施下一轮链接中断时,文档的位置是:
Is this what you are looking for?
MSDN: Custom Control Painting and Rendering
OP Edit: For when Microsoft implements their next round of link breaking, the documentation's location is: