datagridview绘画事件 [英] datagridview paint event

查看:62
本文介绍了datagridview绘画事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有datagridview用作时间表,也有包含课程名称的列表框.我将课程从列表框拖到datagridview.当我将课程从datagridview返回到列表框时,我使用paint事件在datagridview中绘制课程,并且还使用paint事件(将aera绘制回datagridview的颜色).

它的工作很好.当我在datagridview中移动课程,然后我想将另一条课程(从列表框)拖到datagridview中的同一位置时出现问题,仅当我将其移动到datagridview中的另一个位置时,我看不到paint事件datagridview,然后返回到我想要的位置,此时它将绘制我想要的区域.

有没有一种方法可以确定哪个事件更强大?或另一种确保最后发生的事件在最上面的方法.

i have datagridview that i use as a timetable and i also have listbox containing names of courses. i drag courses from listbox to datagridview. i use the paint event to paint courses in the datagridview and i also use the paint event (i paint the aera back to the color of the datagridview)when i move back course form the datagridview to the listbox.

it''s work good. the problem when i move course in the datagridview and then i want to drag another course(from the listbox) to the same place in the datagridview, i can''t see the paint event only if i will move it to another place in the datagridview and then back to the place i wanted just then it will paint the area i want.

there is a way to determine what event more powerful ? or another way to make sure that last event that occurs will be on top ???

推荐答案

没有或多或少强大的事件.您的问题可能会有些棘手,但是如果您理解了这个主意,就相对容易解决.渲染事件实际上是Windows消息WM_PAINT,这是非常特殊的,因为Windows优化了消息的这一部分以避免双重重画.您可以通过调用Control.Invalidate来明确发送此消息.带有参数(< core> Rectangle或Region
Windows OR(set-theory disjunction )对所有无效区域进行优化,并通过立即重新绘制无效区域的并集的方式来优化消息传递,而无需等待消息队列.

因此,这是解决您的问题的想法.您需要处理其他一些事件,这些事件会改变选择范围,也许还有一些其他事件.开发时会看到它.这也取决于您如何呈现控件.在事件处理程序中,您需要为控件的适当区域调用Control.Invalidate.例如,如果您更改选择,则可以使用其他选择模式.受影响的区域可以是单独的单元格,也可以是整行.因此,您应该使失去选择的区域无效,并立即使获得选择的区域无效.使用这种技术;您会发现它可以解决您的问题.

—SA
There is no such thing as more or less powerful event. Your problem can be a bit tricky, but it''s relatively easy to solve if you understand the idea. Rendering event is actually the Windows message WM_PAINT, which is very special, because Windows optimizes this part of messaging to avoid double re-painting. You can cause sending this message explicitly by calling Control.Invalidate. The Invalidate methods with a parameter (<core>Rectangle or Region help to do it with better performance be invalidating only a part of the scene.

Windows ORs (set-theory disjunction) all the invalidated regions and optimizes the messaging the way the union of the invalidated areas is re-painted at once, but without waiting in the message queue.

So, here is the idea for solving you problem. You need to handle some other events, the events changing selection and perhaps some others. You will see it when you develop; it also depends on how you render the control. In the event handlers, you would need to call Control.Invalidate for appropriate areas of your control. For example, if you change selection, you can use different selection mode. The affected area could be either a separate cell or entire row. So, you should invalidate the area which lost selection and immediately the area which got selection. Use this technique; and you will see that it solves your problem.

—SA


这篇关于datagridview绘画事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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