unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus, ComCtrls;
type
TForm1 =
class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
TabSheet4: TTabSheet;
PopupMenu1: TPopupMenu;
pmTabSheet: TMenuItem;
procedure PageControl1ContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
private
{ Private-Deklarationen }
function InRect(X,Y : Integer; R : TRect): Boolean;
function GetTabSheet(PageControl : TPageControl; Position : TPoint) : TTabSheet;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function TForm1.GetTabSheet(PageControl: TPageControl; Position: TPoint): TTabSheet;
var
iCnt : Integer;
begin
Result:=Nil;
For iCnt:=0
to PageControl.PageCount-1
do
begin
If InRect(Position.X,Position.Y,PageControl.TabRect(iCnt))
then
begin
Result:=PageControl.Pages[iCnt];
Exit;
end;
end;
end;
function TForm1.InRect(X, Y: Integer; R: TRect): Boolean;
begin
result := (X >= R.Left)
and (X <= R.Right)
and
(Y >= R.Top)
and (Y <= R.Bottom);
end;
procedure TForm1.PageControl1ContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
var
TabSheet : TTabSheet;
begin
TabSheet:=GetTabSheet(PageControl1,MousePos);
If TabSheet<>
Nil then // Nur <> Nil wenn im TabRect geklickt wurde !!!
pmTabSheet.Caption:=TabSheet.Caption
else
pmTabSheet.Caption:=PageControl1.ActivePage.Caption
end;
end.