[英]PictureBox paint event executing twice
I added a picture box to a WinForms form and added a paint event. 我在WinForms窗体中添加了一个图片框,并添加了一个paint事件。 When I debug it, I see that the paint event is called twice.
当我调试它时,我看到paint事件被调用了两次。
How can I fix it? 我该如何解决?
The picture box control is a relatively loose wrapper around Windows paint cycles and the WM_PAINT
event. 图片框控件是围绕Windows绘制周期和
WM_PAINT
事件的一个相对松散的包装。
The WM_PAINT
event is a queued message that the system places in your applications message queue whenever it deems that a window's drawing surface is invalid. WM_PAINT
事件是排队的消息,只要系统认为窗口的绘图表面无效,系统就会将其放入应用程序消息队列中。 This can happen for many reasons: 发生这种情况的原因有很多:
Invalidate
which ultimately calls the Win32 InvalidateRect
function. Invalidate
来使窗口无效,该Invalidate
最终将调用Win32 InvalidateRect
函数。 So, the natural conclusion of this is that your picture box paint handler needs to be written under the assumption that it will be called multiple times. 因此,自然的结论是您的图片框绘画处理程序需要在被多次调用的假设下编写。
The paint event is fired on every redraw which is quite often. 每次重新绘制时都会触发一次paint事件。 The code in your paint event handler should be able to cope with it being called n-times.
绘制事件处理程序中的代码应能够应对它,称为n次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.