覆盖OnPaint [英] Override OnPaint
问题描述
如果我重写OnPaint并在控件上绘制一个正方形,当我在设计器中预览它时如何显示e.graphics.draw ...?
If I override OnPaint and draw a square on the control, how do I get that e.graphics.draw... to show up when I'm previewing it in the designer?
推荐答案
http:/ /msdn.microsoft.com/zh-CN/magazine/cc164048.aspx
http://msdn.microsoft.com/zh-CN/magazine/cc164145.aspx
虽然您可以手动向
Control.OnPaint注册以添加设计
时间UI,但您会发现覆盖
OnPaintAdornments是一个更好的选择
是因为仅在
控件的设计时/运行时UI绘制了
之后才调用它,让您为
锦上添花(请参见图20)。只需
将DesignerAttribute添加到
ClockControl类即可完成
关联:复制代码
While you could manually register with Control.OnPaint to add your design time UI, you'll find that overriding OnPaintAdornments is a better option because it is only called after the control's design-time/run-time UI is painted, letting you put the icing on the cake (see Figure 20). Simply adding DesignerAttribute to the ClockControl class completes the association: Copy Code
[
Designer(typeof(ClockControlDesigner ))
]类ClockControl:控件{...}
[ Designer(typeof(ClockControlDesigner)) ] class ClockControl : Control { ... }
这篇关于覆盖OnPaint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!