program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
object Form1: TForm1
Left = 192
Top = 88
Width = 689
Height = 523
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
Visible = True
PixelsPerInch = 96
TextHeight = 13
object PageControl1: TPageControl
Left = 96
Top = 40
Width = 465
Height = 329
TabOrder = 0
end
object Button1: TButton
Left = 280
Top = 392
Width = 75
Height = 25
Caption = '新建'
TabOrder = 1
OnClick = Button1Click
end
end
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
PageControl1: TPageControl;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
procedure FreeTabSheet(Sheet: TWinControl);
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Form2: TForm2;
TabSheet: TTabSheet;
begin
TabSheet := TTabSheet.Create(PageControl1);
TabSheet.PageControl := PageControl1;
Form2 := TForm2.Create(TabSheet);
TabSheet.Caption := Form2.Caption;
Form2.Parent := TabSheet;
Form2.Visible := True;
PageControl1.ActivePage := TabSheet;
end;
procedure TForm1.FreeTabSheet(Sheet: TWinControl);
begin
if PageControl1.ActivePage = Sheet then
if PageControl1.PageCount = 1 then
PageControl1.Visible := False;
Sheet.Free;
end;
end.
object Form2: TForm2
Left = 609
Top = 284
Align = alClient
BorderStyle = bsNone
Caption = 'Form2'
ClientHeight = 155
ClientWidth = 399
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 24
Top = 24
Width = 75
Height = 25
Caption = '关闭'
TabOrder = 0
OnClick = Button1Click
end
end
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses Unit1;
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
Form1.FreeTabSheet(Parent);
end;
end.