如何在TDbGrid.OnColumnMoved中放弃鼠标单击 [英] How to discard mouse click in TDbGrid.OnColumnMoved
问题描述
在 TDbGrid.OnColumnMoved
事件处理程序中,我调整了一些列标题颜色。
In a TDbGrid.OnColumnMoved
event handler, I adjust some column headings colors.
我也使用了网格的 OnTitleClicked
事件弹出一个(排序列)菜单。
I also use the grid's OnTitleClicked
event to pop-up a (sort column) menu.
不幸的是,在用户拖动列之后并且 OnColumnMoved
完成后,VCL调用 OnTitleClicked
。这意味着我的排序顺序弹出窗口会在拖动列后出现。
Unfortunately, after the user drags a column and OnColumnMoved
is finished, the VCL calls OnTitleClicked
. This means my sort-order pop-up appears after column dragging.
OnColumnMoved
中是否可以清除鼠标事件队列,以便不会调用 OnTitleClicked
?
Is there a way in OnColumnMoved
I can clear the mouse event queue so that OnTitleClicked
doesn't get called?
该线程包含以下代码,但我没有 Msg
in OnTitleClicked
。
This thread has this code, but I don't have a Msg
in OnTitleClicked
.
while PeekMessage(Msg, 0, WM_MOUSEFIRST, WM_MOUSELAST,
PM_REMOVE or PM_NOYIELD) do;
(如果无法执行此操作,则没什么大不了。我可以在 OnColumnMoved
,这样 OnTitleClick
会忽略下一个调用。)
(If there's no way to do this, it's not big deal. I can set a flag in OnColumnMoved
so that OnTitleClick
ignores the next call to it.)
推荐答案
如对该问题的评论中所述,您将自己为 PeekMessage
提供 OnTitleClick
的消息,因为这是引发两个事件的同一条消息。如果已拖动列,则VCL响应 WM_LBUTTONUP
消息执行列移动。稍后在处理同一条消息时,将调用 OnTitleClick
。
As mentioned in comments to the question, you would supply the 'Msg' for PeekMessage
yourself (var Msg: TMsg
). But discarding the message that triggers OnTitleClick
is not possible because it is the same message that fires both events. VCL carries out column moving in response to a WM_LBUTTONUP
message if a column has been dragged. Later during the handling of the same message OnTitleClick
is called.
IOW,而您可以从消息中删除消息 PeekMessage
排队,触发 OnTitleClick
的消息已经分派,因为我们在 OnColumnMoved中
处理程序。
IOW, while you can remove messages from the message queue with PeekMessage
, the message that triggers OnTitleClick
is already dispatched since we are in an OnColumnMoved
handler.
最简单的方法就像您所讲的那样设置标志。
Easiest approach looks like setting the flag as you've told.
这篇关于如何在TDbGrid.OnColumnMoved中放弃鼠标单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!