uses CommCtrl;
-----------------------------------------------------------------------------
procedure TForm1.PageControl1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
//マウスの左ボタンを押したまま、5px以上移動したらドラッグスタート
if Button =mbLeft then
PageControl1.BeginDrag(False, 5);
end;
//ドラッグ中のカーソルがコントロール上にきたときの処理
procedure TForm1.PageControl1DragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
var
i :integer;
R :TRect;
begin
if Sender is TPageControl then
begin
Accept :=true;
//挿入される位置を線で描画(おまけです。必要ないなら削除可)
with PageControl1 do begin
Refresh;
for i :=0 to PageCount -1 do
begin
PerForm(TCM_GETITEMRECT, i,Integer(@R));
if PtinRect(R, Point(X, Y)) and (i <> ActivePage.PageIndex) then
begin
with (Sender as TPageControl).Canvas do begin
Pen.Color :=clBlack;
Pen.Width :=2;
{挿入される位置に応じてタブの左右どちらに
線を描画するか変える}
if i < ActivePage.PageIndex then
begin
MoveTo(R.Left +1, R.Top);
LineTo(R.Left +1, R.Bottom);
end
else begin
MoveTo(R.Right -1, R.Top);
LineTo(R.Right -1, R.Bottom);
end;
Exit;
end;
end;
end;
end;
end;
end;
//ドロップ時の処理
procedure TForm1.PageControl1DragDrop(Sender, Source: TObject; X,
Y: Integer);
var
i :integer;
R :TRect;
begin
with PageControl1 do begin
for i :=0 to PageCount -1 do
begin
//最初のタブから順番にタブの矩形を取得
PerForm(TCM_GETITEMRECT, i,Integer(@R));
//現在のタブ上にマウスがあればアクティブページにセット
if PtinRect(R, Point(X, Y)) then
begin
if i <> ActivePage.PageIndex then
ActivePage.PageIndex :=i;
Exit;
end;
end;
end;
end; |