最近要實作一個系統,就是通過將表格表頭拖拽的Panel后,自動生成控制元件, 可是一直找不到表頭的拖拽事件?
我用的 Dev的 CxGrid控制元件,

如圖,我想把表頭拖拽的紅框處。
而CxGrid中的表頭只能拖動到 分組(Group) 或者 改變序列中,滑鼠移動到其他地方都會變為不可拖動。
我嘗試在cxGridDBTableView中 的和Drag有關的事件,結果發現只對,Drag事件只對表格內記錄起作用,表格的表頭拖動,還是無效。

然后有才列上想辦法, 結果發現列沒有相關的Drag事件。
。搞了4、5個小時,只好去 原始碼去除錯’
發現點擊表頭是首先執行了 TCxControl .MouseDown 事件,也的確在這個事件中開始了Drag動作

這個事件里以及獲取到 Drag的類了

結果,到后面又發現了,TcxGridColumnHeaderMovingObject 這個類,,, 然后我就暈了,, 轉來轉去,找不到頭緒了。
procedure TcxGridColumnHeaderMovingObject.CalculateDestParams(AHitTest: TcxCustomGridHitTest;
out AContainerKind: TcxGridItemContainerKind; out AZone: TcxGridItemContainerZone);
begin
inherited;
if AContainerKind = ckNone then
begin
AZone := ViewInfo.GroupByBoxViewInfo.GetZone(AHitTest.Pos);
if AZone = nil then
begin
AZone := ViewInfo.HeaderViewInfo.GetZone(AHitTest.Pos);
if AZone <> nil then
AContainerKind := ckHeader;
end
else
AContainerKind := ckGroupByBox;
end;
end;
function TcxCustomGridController.StartDragAndDrop(const P: TPoint): Boolean;
var
AHitTest: TcxCustomGridHitTest;
begin
AHitTest := ViewInfo.GetHitTest(P);
Result := CanHandleHitTest(AHitTest);
if Result then
begin
Result := AHitTest.DragAndDropObjectClass <> nil;
if Result then
begin
CancelHint;
DragAndDropObjectClass := AHitTest.DragAndDropObjectClass;
DragAndDropObject.Init(P, AHitTest);
end;
end;
end;
procedure TcxControl.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure TcxControl.CMMouseEnter(var Message: TMessage);
begin
inherited;
if Message.lParam = 0 then
MouseEnter(Self)
else
MouseEnter(TControl(Message.lParam));
end;
procedure TcxDragAndDropObject.DragAndDrop(const P: TPoint; var Accepted: Boolean);
begin
Dirty := False;
Screen.Cursor := GetDragAndDropCursor(Accepted);
end;
procedure TcxControl.DoMouseEnter(AControl: TControl);
begin
if ((AControl = Self) or (AControl = nil)) and (FMouseEnterCounter = 0) then
begin
Inc(FMouseEnterCounter);
dxCallNotify(FOnMouseEnter, Self);
end;
end;
這是我抓出來的我覺得是關鍵性的代碼。。
我還嘗試通過 表頭拖拽時,游標的變化,來找關鍵性的代碼。結果也是沒有識訓。
,而且,我到現在先沒搞明白,誰去觸發的TcxControl.MouseDown事件? Column不是TcxControl類的, TableView也不是,
只有CxGrid1的祖先類是TCxControl,可是為什么我在Cxgrid1的MouseDown事件中,無法捕獲呢?
放棄這條方式之后,我想通過 截獲Windows 滑鼠 訊息來達到目的, 訊息能截獲,可是卻一直無法判斷,Column 列 是不是正在處于被拖拽的狀態,

想請教各位大神,有什么辦法沒有。
uj5u.com熱心網友回復:
HotTrack 屬性啊轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/41296.html
標籤:VCL組件開發及應用
