Difference between revisions of "TNotebook"

From Lazarus wiki
m
(TNotebook)
Line 1: Line 1:
 
{{TNotebook}}
 
{{TNotebook}}
  
'''TNoteBook''' [[image:tnotebook.png]] is a component that provides a container to hold pages, much like a real-world notebook. TNoteBook is a descendant of [[TWinControl]] and is available under the [[Additional tab]] of the [[Component Palette]].  
+
[[image:tnotebook.png]] '''TNoteBook''' is a component that provides a container to hold a variety of controls arranged in pages, much like a real-world notebook. It is a descendant of [[TWinControl]] and is available under the [[Additional tab]] of the [[Component Palette]].  
  
Pages from a TNotebook are accessible through its ''Pages'' property. The ''PageIndex'' property determines which page is on top.
+
Unlike [[TPageControl]] the <tt>TNotebook</tt> does not have tabs. All pages of the <tt>TNotebook</tt> are listed by the <tt>Pages</tt> property. At designtime the pages are listed in the object tree of the Object Inspector under the Notebook node; here the developer can easily switch from page to page. At runtime, special code must be provided to show a specific page; the <tt>PageIndex</tt> property determines which page is currently visible.
 +
 
 +
<tt>TNotebook</tt> can be used to create tabless, wizard-like dialogs in which "Forward"/"Backward" buttons are available to move from page to page:
 +
<syntaxhighlight lang=Pascal>procedure TForm1.ForwardBtnClick(Sender: TObject);
 +
begin
 +
  if Notebook1.PageIndex < Notebook1.PageCount-1 then
 +
    Notebook1.PageIndex := Notebook1.PageIndex + 1;
 +
end;
 +
 
 +
procedure TForm1.BackwardBtnClick(Sender: TObject);
 +
begin
 +
  if Notebook1.PageIndex > 0 then
 +
    Notebook1.PageIndex := Notebook1.PageIndex - 1;
 +
end; 
 +
</syntaxhighlight>
 +
 
 +
Pages can be added at designtime by right-clicking on the <tt>TNotebook</tt> component and selecting ''Add Page'' from the context menu. Correspondingly a page can be removed here by the menu item ''Delete Page''.
 +
 
 +
At runtime, a page is added by calling <tt>Notebook.Add('new pagename')</tt> with the name of the new page as parameter; the function returns the index of the new page. The new page itself can be addressed by using the property <tt>Notebook.Page[newindex]</tt> -- please note the singular here!
 +
 
 +
The following example adds a new page and puts a <tt>TMemo</tt> on it:
 +
<syntaxhighlight lang=Pascal>procedure TForm1.NewPageBtnClick(Sender: TObject);
 +
var
 +
  newIndex: Integer;
 +
begin
 +
  newIndex := Notebook1.Pages.Add('New Page');  // use plural!
 +
  with TMemo.Create(self) do
 +
  begin
 +
    Parent := Notebook1.Page[newIndex];          // use singular!
 +
    Align := alClient;
 +
  end;
 +
end; </syntaxhighlight>
  
 
==See also==
 
==See also==

Revision as of 20:29, 6 February 2021

English (en) français (fr) русский (ru)

tnotebook.png TNoteBook is a component that provides a container to hold a variety of controls arranged in pages, much like a real-world notebook. It is a descendant of TWinControl and is available under the Additional tab of the Component Palette.

Unlike TPageControl the TNotebook does not have tabs. All pages of the TNotebook are listed by the Pages property. At designtime the pages are listed in the object tree of the Object Inspector under the Notebook node; here the developer can easily switch from page to page. At runtime, special code must be provided to show a specific page; the PageIndex property determines which page is currently visible.

TNotebook can be used to create tabless, wizard-like dialogs in which "Forward"/"Backward" buttons are available to move from page to page:

procedure TForm1.ForwardBtnClick(Sender: TObject);
begin
  if Notebook1.PageIndex < Notebook1.PageCount-1 then
    Notebook1.PageIndex := Notebook1.PageIndex + 1;
end;

procedure TForm1.BackwardBtnClick(Sender: TObject);
begin
  if Notebook1.PageIndex > 0 then
    Notebook1.PageIndex := Notebook1.PageIndex - 1;
end;

Pages can be added at designtime by right-clicking on the TNotebook component and selecting Add Page from the context menu. Correspondingly a page can be removed here by the menu item Delete Page.

At runtime, a page is added by calling Notebook.Add('new pagename') with the name of the new page as parameter; the function returns the index of the new page. The new page itself can be addressed by using the property Notebook.Page[newindex] -- please note the singular here!

The following example adds a new page and puts a TMemo on it:

procedure TForm1.NewPageBtnClick(Sender: TObject);
var
  newIndex: Integer;
begin
  newIndex := Notebook1.Pages.Add('New Page');   // use plural!
  with TMemo.Create(self) do
  begin
    Parent := Notebook1.Page[newIndex];           // use singular!
    Align := alClient;
  end;
end;

See also


LCL Components
Component Tab Components
Standard TMainMenu • TPopupMenu • TButton • TLabel • TEdit • TMemo • TToggleBox • TCheckBox • TRadioButton • TListBox • TComboBox • TScrollBar • TGroupBox • TRadioGroup • TCheckGroup • TPanel • TFrame • TActionList
Additional TBitBtn • TSpeedButton • TStaticText • TImage • TShape • TBevel • TPaintBox • TNotebook • TLabeledEdit • TSplitter • TTrayIcon • TControlBar • TFlowPanel • TMaskEdit • TCheckListBox • TScrollBox • TApplicationProperties • TStringGrid • TDrawGrid • TPairSplitter • TColorBox • TColorListBox • TValueListEditor
Common Controls TTrackBar • TProgressBar • TTreeView • TListView • TStatusBar • TToolBar • TCoolBar • TUpDown • TPageControl • TTabControl • THeaderControl • TImageList • TPopupNotifier • TDateTimePicker
Dialogs TOpenDialog • TSaveDialog • TSelectDirectoryDialog • TColorDialog • TFontDialog • TFindDialog • TReplaceDialog • TTaskDialog • TOpenPictureDialog • TSavePictureDialog • TCalendarDialog • TCalculatorDialog • TPrinterSetupDialog • TPrintDialog • TPageSetupDialog
Data Controls TDBNavigator • TDBText • TDBEdit • TDBMemo • TDBImage • TDBListBox • TDBLookupListBox • TDBComboBox • TDBLookupComboBox • TDBCheckBox • TDBRadioGroup • TDBCalendar • TDBGroupBox • TDBGrid • TDBDateTimePicker
Data Access TDataSource • TCSVDataSet • TSdfDataSet • TBufDataset • TFixedFormatDataSet • TDbf • TMemDataset
System TTimer • TIdleTimer • TLazComponentQueue • THTMLHelpDatabase • THTMLBrowserHelpViewer • TAsyncProcess • TProcessUTF8 • TProcess • TSimpleIPCClient • TSimpleIPCServer • TXMLConfig • TEventLog • TServiceManager • TCHMHelpDatabase • TLHelpConnector
Misc TColorButton • TSpinEdit • TFloatSpinEdit • TArrow • TCalendar • TEditButton • TFileNameEdit • TDirectoryEdit • TDateEdit • TTimeEdit • TCalcEdit • TFileListBox • TFilterComboBox • TComboBoxEx • TCheckComboBox • TButtonPanel • TShellTreeView • TShellListView • TXMLPropStorage • TINIPropStorage • TJSONPropStorage • TIDEDialogLayoutStorage • TMRUManager • TStrHolder
LazControls TCheckBoxThemed • TDividerBevel • TExtendedNotebook • TListFilterEdit • TListViewFilterEdit • TLvlGraphControl • TShortPathEdit • TSpinEditEx • TFloatSpinEditEx • TTreeFilterEdit • TExtendedTabControl •
RTTI TTIEdit • TTIComboBox • TTIButton • TTICheckBox • TTILabel • TTIGroupBox • TTIRadioGroup • TTICheckGroup • TTICheckListBox • TTIListBox • TTIMemo • TTICalendar • TTIImage • TTIFloatSpinEdit • TTISpinEdit • TTITrackBar • TTIProgressBar • TTIMaskEdit • TTIColorButton • TMultiPropertyLink • TTIPropertyGrid • TTIGrid
SQLdb TSQLQuery • TSQLTransaction • TSQLScript • TSQLConnector • TMSSQLConnection • TSybaseConnection • TPQConnection • TPQTEventMonitor • TOracleConnection • TODBCConnection • TMySQL40Connection • TMySQL41Connection • TMySQL50Connection • TMySQL51Connection • TMySQL55Connection • TMySQL56Connection • TMySQL57Connection • TSQLite3Connection • TIBConnection • TFBAdmin • TFBEventMonitor • TSQLDBLibraryLoader
Pascal Script TPSScript • TPSScriptDebugger • TPSDllPlugin • TPSImport_Classes • TPSImport_DateUtils • TPSImport_ComObj • TPSImport_DB • TPSImport_Forms • TPSImport_Controls • TPSImport_StdCtrls • TPSCustomPlugin
SynEdit TSynEdit • TSynCompletion • TSynAutoComplete • TSynMacroRecorder • TSynExporterHTML • TSynPluginSyncroEdit • TSynPasSyn • TSynFreePascalSyn • TSynCppSyn • TSynJavaSyn • TSynPerlSyn • TSynHTMLSyn • TSynXMLSyn • TSynLFMSyn • TSynDiffSyn • TSynUNIXShellScriptSyn • TSynCssSyn • TSynPHPSyn • TSynTeXSyn • TSynSQLSyn • TSynPythonSyn • TSynVBSyn • TSynAnySyn • TSynMultiSyn • TSynBatSyn • TSynIniSyn • TSynPoSyn
Chart TChart • TListChartSource • TRandomChartSource • TUserDefinedChartSource • TCalculatedChartSource • TDbChartSource • TChartToolset • TChartAxisTransformations • TChartStyles • TChartLegendPanel • TChartNavScrollBar • TChartNavPanel • TIntervalChartSource • TDateTimeIntervalChartSource • TChartListBox • TChartExtentLink • TChartImageList
IPro TIpFileDataProvider • TIpHttpDataProvider • TIpHtmlPanel
Virtual Controls TVirtualDrawTree • TVirtualStringTree • TVTHeaderPopupMenu