unit ExpertTabSheet;
interface
uses
Windows, Classes, ExtCtrls, Dialogs, ComCtrls, Forms, Buttons,
Controls, SysUtils, Themes, UxTheme, Graphics;
type ETabSheet = Class (TTabSheet)
private
protected
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
procedure OpenWindowTab(PageControl: TPageControl; FormClass: TFormClass; MultiTab: Boolean);
procedure ClickEvent(Sender: TObject);
implementation
constructor ETabSheet.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
end;
destructor ETabSheet.Destroy;
begin
inherited Destroy;
end;
procedure OpenWindowTab(PageControl: TPageControl; FormClass: TFormClass; MultiTab: Boolean);
var
i: Integer;
Form: TForm;
TabSheet: ETabSheet;
ShiftOn: TShiftState;
PPointer: TPoint;
btnClose: TSpeedButton;
TitleBar, ButtonsSet: TPanel;
begin
try
//Cria a TabSheet
TabSheet := ETabSheet.Create(PageControl);
//Verifica se o form já foi criado
Form := FormClass.Create(TabSheet);
for i := 0 to PageControl.ControlCount -1 do
if (PageControl.Pages[i].Caption = Form.Caption) and (MultiTab = False) then
begin
PageControl.ActivePageIndex := i;
exit;
end;
//Cria o Form
TabSheet.PageControl := PageControl;
Form := FormClass.Create(TabSheet);
Form.Parent := TabSheet;
//Cria uma barra de títulos para a TabSheet
TitleBar := TPanel.Create(TabSheet);
TitleBar.Parent := TabSheet;
TitleBar.Align := alTop;
TitleBar.Height := 22;
TitleBar.Caption := Form.Caption;
TitleBar.Color := clWindow;
TitleBar.Visible := True;
//Propriedade do Form
Form.Align := alClient;
Form.BorderStyle := bsNone;
Form.Visible := True;
TabSheet.Caption := Form.Caption;
//Cria um container para os botões
ButtonsSet := TPanel.Create(TitleBar);
ButtonsSet.Parent := TitleBar;
ButtonsSet.Align := alRight;
ButtonsSet.Caption := '';
ButtonsSet.Width := 80;
ButtonsSet.BorderSpacing.Right := 1;
ButtonsSet.BiDiMode := bdRightToLeft;
ButtonsSet.BorderStyle := bsNone;
ButtonsSet.BevelInner := bvNone;
ButtonsSet.BevelOuter := bvNone;
ButtonsSet.Anchors := [akTop,akRight];
ButtonsSet.Color := clNone;
ButtonsSet.Visible := True;
//Cria o botão para fechar a TabSheet
btnClose := TSpeedButton.Create(ButtonsSet);
btnClose.Parent := ButtonsSet;
btnClose.Width := 19;
btnClose.Height := 19;
btnClose.Left := 60;
btnClose.BorderSpacing.Around := 1;
btnClose.BorderSpacing.InnerBorder := 0;
btnClose.BorderSpacing.CellAlignHorizontal := ccaCenter;
btnClose.BorderSpacing.CellAlignVertical := ccaCenter;
btnClose.Align := alNone;
btnClose.Anchors := [akTop,akRight];
btnClose.Caption := 'X';
btnClose.Hint := 'Fechar aba';
btnClose.Transparent := True;
btnClose.ShowHint := True;
btnClose.Visible := True;
btnClose.OnClick := @ClickEvent;
//Coloca o foco na TabSheet aberta
PageControl.ActivePage := TabSheet;
Form.SetFocus;
except
Form.Free;
end;
end;
procedure ClickEvent(Sender: TObject);
begin
ShowMessage('Aqui fica a rotina para destruir a TabSheet e o Form');
end;
initialization
ETabSheet.ClassName;
end.