Examples, NoteBk: converted nested Notebook to TPageControl and restored features, which were removed in r28916 #76f0a18ff0

git-svn-id: trunk@29571 -
This commit is contained in:
maxim 2011-02-15 22:17:28 +00:00
parent 7d1c2d987a
commit 363abb927f
2 changed files with 103 additions and 60 deletions

View File

@ -1,38 +1,18 @@
<?xml version="1.0"?>
<CONFIG>
<ProjectOptions>
<PathDelim Value="/"/>
<Version Value="5"/>
<Version Value="9"/>
<General>
<Flags>
<SaveOnlyProjectUnits Value="True"/>
<LRSInOutputDirectory Value="False"/>
</Flags>
<MainUnit Value="0"/>
<TargetFileExt Value=""/>
<ActiveEditorIndexAtStart Value="1"/>
<ActiveWindowIndexAtStart Value="0"/>
</General>
<Units Count="2">
<Unit0>
<CursorPos X="8" Y="29"/>
<EditorIndex Value="0"/>
<Filename Value="notebk.pp"/>
<IsPartOfProject Value="True"/>
<Loaded Value="True"/>
<TopLine Value="1"/>
<UnitName Value="NoteBk"/>
<UsageCount Value="20"/>
</Unit0>
<Unit1>
<CursorPos X="35" Y="36"/>
<EditorIndex Value="1"/>
<Filename Value="notebku.pp"/>
<IsPartOfProject Value="True"/>
<Loaded Value="True"/>
<TopLine Value="1"/>
<UnitName Value="notebku"/>
<UsageCount Value="20"/>
</Unit1>
</Units>
<BuildModes Count="1">
<Item1 Name="default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<IgnoreBinaries Value="False"/>
@ -50,15 +30,43 @@
<PackageName Value="LCL"/>
</Item1>
</RequiredPackages>
<Units Count="2">
<Unit0>
<Filename Value="notebk.pp"/>
<IsPartOfProject Value="True"/>
<UnitName Value="NoteBk"/>
<EditorIndex Value="0"/>
<WindowIndex Value="0"/>
<TopLine Value="1"/>
<CursorPos X="8" Y="29"/>
<UsageCount Value="21"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit0>
<Unit1>
<Filename Value="notebku.pp"/>
<IsPartOfProject Value="True"/>
<UnitName Value="notebku"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="1"/>
<WindowIndex Value="0"/>
<TopLine Value="253"/>
<CursorPos X="38" Y="285"/>
<UsageCount Value="21"/>
<Loaded Value="True"/>
</Unit1>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="5"/>
<Version Value="10"/>
<SearchPaths>
<SrcPath Value="$(LazarusDir)/lcl/;$(LazarusDir)/lcl/interfaces/$(LCLWidgetType)/"/>
<SrcPath Value="$(LazarusDir)/lcl;$(LazarusDir)/lcl/interfaces/$(LCLWidgetType)"/>
</SearchPaths>
<CodeGeneration>
<Generate Value="Faster"/>
</CodeGeneration>
<Parsing>
<SyntaxOptions>
<UseAnsiStrings Value="False"/>
</SyntaxOptions>
</Parsing>
<Linking>
<Options>
<Win32>

View File

@ -25,7 +25,7 @@ unit notebku;
interface
uses Classes, SysUtils, Controls, Forms, ExtCtrls, Buttons, StdCtrls;
uses Classes, SysUtils, Controls, Forms, ExtCtrls, Buttons, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
@ -33,7 +33,7 @@ type
private
public
fNotebk: TNotebook;
fNotebook: TNotebook;
fNotebook: TPageControl;
fButton1: TButton;
fButton2: TButton;
fButton3: TButton;
@ -49,7 +49,9 @@ type
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
end;
var
@ -64,9 +66,11 @@ begin
end;
constructor TForm1.Create(AOwner: TComponent);
var
i: integer;
begin
inherited Create(AOwner);
Caption := 'Notebook Test';
Caption := 'Notebook/PageControl Test';
Width := 300;
Height := 400;
Left := 200;
@ -82,31 +86,23 @@ begin
Top :=0;
Width := Self.Width;
Height := Self.Height;
if PageCount>0 then
Pages.Strings[0] := 'Page 1'
else
Pages.Add('Page 1');
Pages.Add('Page 2');
Pages.Add('Page 3');
Pages.Add('Page 4');
Pages.Add('Page 5');
for i:=1 to 5 do
Pages.Add('Page '+IntToStr(i));
end;
fNotebk.Page[4].OnResize:=@fNotebkResize;
// Create the Tabbed Notebook
fNotebook := TNotebook.Create(Self);
// Create the nested PageControl
fNotebook := TPageControl.Create(Self);
with fNotebook do
begin
Parent := fNotebk.Page[4];
if PageCount>0 then
Pages.Strings[0] := 'Page 1'
else
Pages.Add('Page 1');
Pages.Add('Page 2');
Pages.Add('Page 3');
Pages.Add('Page 4');
Pages.Add('Page 5');
for i:=1 to 5 do
with TTabSheet.Create(fNotebook) do
begin
PageControl := fNotebook;
Caption := 'Page '+IntToStr(i);
end;
end;
{ Create Goto First Page Button on last page of Notebook
@ -232,18 +228,18 @@ begin
end;
// Create Show/Hide Tabs Button on first page of TabbedNotebook
{ fButton4 := TButton.Create(fNotebook.Page[0]);
fButton4 := TButton.Create(fNotebook.Page[0]);
with fButton4 do
begin
Parent := fNotebook.Page[0];
OnClick := @Button4Click;
Width := 90;
Height := 23;
left := (250 {Parent.Widht} - Width) div 2;
left := (250 {Parent.Width} - Width) div 2;
top := 150;
Caption := 'Hide Tabs';
Show;
end;}
end;
// Create Delete Page Button on third page of TabbedNotebook
fButton5 := TButton.Create(fNotebook.Page[2]);
@ -253,12 +249,26 @@ begin
OnClick := @Button5Click;
Width := 120;
Height := 23;
left := (250 {Parent.Widht} - Width) div 2;
left := (250 {Parent.Width} - Width) div 2;
top := 100;
Caption := 'Delete Page';
Show;
end;
// Create Set Tabs Position Button on first page of TabbedNotebook
fButton6 := TButton.Create(fNotebook.Page[0]);
with fButton6 do
begin
Parent := fNotebook.Page[0];
OnClick := @Button6Click;
Width := 150;
Height := 23;
left := (250 {Parent.Widht} - Width) div 2;
top := 190;
Caption := 'Set Tab Position';
Show;
end;
// Goto the first page of the Notebook
fNotebk.PageIndex := 0;
end;
@ -281,20 +291,45 @@ begin
Close;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
//writeln('Show/Hide Tabs Button Clicked');
fNotebook.ShowTabs := not fNotebook.ShowTabs;
if (fNotebook.ShowTabs) then
fButton4.Caption := 'Hide Tabs'
else
fButton4.Caption := 'Show Tabs';
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
//writeln('Delete Page Button Clicked');
if (fNotebook.Pages.Count > 1) then
if (fNotebook.PageCount > 1) then
begin
// Make sure we don't delete the page with the delete button on it
if (fNotebook.PageIndex = fNotebook.Pages.Count - 1) then
fNotebook.Pages.Delete(fNotebook.Pages.Count - 2)
if (fNotebook.PageIndex = fNotebook.PageCount - 1) then
fNotebook.Pages[fNotebook.PageCount - 2].Free
else
fNotebook.Pages.Delete(fNotebook.Pages.Count - 1);
fNotebook.Pages[fNotebook.PageCount - 1].Free;
end;
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
//writeln('Set Tab Position Button Clicked');
if fNotebook.TabPosition = tpTop then
fNotebook.TabPosition := tpRight
else if fNotebook.TabPosition = tpRight then
fNotebook.TabPosition := tpBottom
else if fNotebook.TabPosition = tpBottom then
fNotebook.TabPosition := tpLeft
else if fNotebook.TabPosition = tpLeft then
fNotebook.TabPosition := tpTop;
end;
end.