我大概了解一下: 主要通过三个事件来处理拖动的组件 MouseDown,DragOver,DragDrop:这三个事件分别对应拖动组件的三个过程。举个例子来说 (win3.1的TTabSet组件的拖动)procedure TForm1.TabSet1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var DragItem: Integer; begin if Button = mbLeft then begin DragItem := TabSet1.ItemAtPos(Point(X, Y)); if (DragItem > -1) and (DragItem < TabSet1.Tabs.Count) then TabSet1.BeginDrag(False); end; end; procedure TForm1.TabSet1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); var DropPos: Integer; begin if Source = TabSet1 then begin DropPos := TabSet1.ItemAtPos(Point(X, Y)); Accept := (DropPos > -1) and (DropPos <> TabSet1.TabIndex) and (DropPos < TabSet1.Tabs.Count); end else Accept := False; end; procedure TForm1.TabSet1DragDrop(Sender, Source: TObject; X, Y: Integer); var OldPos: Integer; NewPos: Integer; begin if Source = TabSet1 then begin OldPos := TabSet1.TabIndex; NewPos := TabSet1.ItemAtPos(Point(X, Y)); if (NewPos > -1) and (NewPos <> OldPos) then TabSet1.Tabs.Move(OldPos, NewPos); end; end;效果不明显,高手们能提供更好的方法啊!!
主要通过三个事件来处理拖动的组件
MouseDown,DragOver,DragDrop:这三个事件分别对应拖动组件的三个过程。举个例子来说 (win3.1的TTabSet组件的拖动)procedure TForm1.TabSet1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
DragItem: Integer;
begin
if Button = mbLeft then
begin
DragItem := TabSet1.ItemAtPos(Point(X, Y));
if (DragItem > -1) and (DragItem < TabSet1.Tabs.Count) then
TabSet1.BeginDrag(False);
end;
end;
procedure TForm1.TabSet1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
var
DropPos: Integer;
begin
if Source = TabSet1 then
begin
DropPos := TabSet1.ItemAtPos(Point(X, Y));
Accept := (DropPos > -1) and (DropPos <> TabSet1.TabIndex) and (DropPos < TabSet1.Tabs.Count);
end
else
Accept := False;
end;
procedure TForm1.TabSet1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
OldPos: Integer;
NewPos: Integer;
begin
if Source = TabSet1 then
begin
OldPos := TabSet1.TabIndex;
NewPos := TabSet1.ItemAtPos(Point(X, Y));
if (NewPos > -1) and (NewPos <> OldPos) then
TabSet1.Tabs.Move(OldPos, NewPos);
end;
end;效果不明显,高手们能提供更好的方法啊!!