的OnPaint事件(失效)一段正常运行后更改执行顺序(运行时) [英] Onpaint events (invalidated) changing execution order after a period normal operation (runtime)

查看:369
本文介绍了的OnPaint事件(失效)一段正常运行后更改执行顺序(运行时)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过他们的油漆彩绘事件3的数据图。
当我有需要插入图表我所说的控制无效()命令的数据。

I have 3 data graphs that are painted via the their paint events. When I have data that I need to insert into the graph I call the controls invalidate() command.

第一个控件的Paint事件实际上创建位图缓存对其他2图,以避免重复长的循环。

The first control's paint event actually creates a bitmap buffer for the other 2 graphs to avoid repeating a long loop.

因此,无效命令是在一个特定的顺序(1,2,3)。这种运作良好,但是当绘制数据到达图形窗口(图片框),其中数据通常会开始滚动,油漆事件开始以错误的顺序(2,3,1)发射的结束。

So the invalidate commands are in a specific order (1,2,3). This works well, however when the graphed data reaches the end of the graph window (PictureBox) where the data would normally start scrolling, the paint events begin firing in the wrong order (2,3,1).

有过这个人之前来的?为什么会这样是这样吗?

has anyone came across this before? why might this be happening?

推荐答案

更改代码,以便调用之前的Invalidate 在任何三个控件,你创建一个共享位图缓存(可以想象作为控件类的静态成员),而然后的通话的Invalidate 在每个控件。在控制的油漆事件中,你就可以使用静态位图缓存,并且它不会不管以何种顺序油漆事件触发。

Change your code so that before calling Invalidate on any of the three controls, you create the one shared bitmap buffer (conceivably as a static member of your control class), and then call Invalidate on each of the controls. Within the control's Paint event you can then use the static bitmap buffer, and it won't matter in which order the Paint events fire.

当你调用的Invalidate 上的控件,你基本上是告诉操作系统发送WM_PAINT消息到该控件。因为它是Windows消息,它保证只要Windows得到周围做交付。在你的情况,他们一般在接到订单交付,但有时他们只是不会

When you call Invalidate on a control, you're basically telling the OS to send a WM_PAINT message to that control. Because it's a Windows message, it's guaranteed to be delivered whenever Windows gets around to doing it. In your case, they're usually delivered in the order received, but sometimes they just won't be.

另一个要考虑你的代码:当你的地方控件的油漆事件处理中相对复杂的绘制代码(或直接从油漆名为事件处理方法内部),每当控制失效的出于任何原因的,也就是说,当你调用的Invalidate 中的代码将运行该代码将执行,但它也将运行时拖过控制另一扇窗。

One other thing to consider with your code: when you place relatively complex drawing code inside your control's Paint event handler (or inside a method called directly from the Paint event handler), this code will execute whenever the control is invalidated for any reason, meaning that the code will run when you call Invalidate, but it will also run whenever another window is dragged over the control.

对于复杂,费时的图形,它总是最好到一个隐藏缓冲区执行复杂的渲染(A 位图或无形的图片框或其他),然后在控件的油漆事件做从隐藏缓冲区的简单拷贝到可见的窗口(使用 Graphics.DrawImage 的BitBlt 或其他)。

For complex, time-consuming graphics, it's always best to perform the complex rendering on a hidden buffer (a Bitmap or an invisible PictureBox or whatever), and then in the control's Paint event do a simple copy from the hidden buffer to the visible window (using Graphics.DrawImage or BitBlt or whatever).

这个方法也可以让你避免闪烁,如果你在你画的缓冲区和可见的窗口(因此双缓冲)之间添加第二个缓冲区。主缓冲区你完成绘图后,您将它复制到第二个缓冲区。在控制的油漆时,您从第二个缓冲到可视窗口复制。

This approach also allows you to avoid flicker, if you add a second buffer in between the buffer you draw on and the visible window (hence "double buffering"). After you complete drawing on the main buffer, you copy it onto the second buffer. In the control's Paint event, you copy from the second buffer onto the visible window.

这篇关于的OnPaint事件(失效)一段正常运行后更改执行顺序(运行时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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