Difference between revisions of "TImageList"

From Lazarus wiki
Jump to navigationJump to search
m
Line 1: Line 1:
'''TImageList''' is a list of [[TImage|images]], e.g. for creating a [[TToolBar|Toolbar]].
+
'''TImageList''' [[image|timagelist.png]] is a component that provides a list of [[TImage|images]] that can be used within other components like  [[TToolBar]] of [[TActionList]].
 
 
[[File:Win7LazarusStdToolbar.png|Toolbars use ImageLists]]
 
 
 
See [[doc:lcl//controls/timagelist.html|TImageList]] in the LCL reference for details.
 
 
 
  
 
== Example with ComboBox ==
 
== Example with ComboBox ==
 +
To use TImageList, drop an TImageList object onto the form. In this example we need six images.
  
To use TImageList, drop an ImageList object onto the form. In this example we need six images.
+
All images must be the same size. If two sizes of image are to be used, then two TImageLists must be used.
 
 
All images must be the same size. If two sizes of image are to be used, then two ImageLists must be used.
 
  
 
Set the height and width of the images in the Object Inspector; In this case 50px wide by 18px high.
 
Set the height and width of the images in the Object Inspector; In this case 50px wide by 18px high.
Line 16: Line 10:
 
Set Style to csOwnerDrawFixed.
 
Set Style to csOwnerDrawFixed.
  
Double-click on the ImageList icon to open the ImageList editor. Make sure that the icons show correctly when selected. If they are smaller than expected, check the size in the Object Inspector <F11>. You may have to reload the images.
+
Double-click on the TImageList icon to open the TImageList editor. Make sure that the icons show correctly when selected. If they are smaller than expected, check the size in the Object Inspector <F11>. You may have to reload the images.
 +
 
 
[[File:ImageListEd.png]]
 
[[File:ImageListEd.png]]
  
Line 23: Line 18:
 
In the FormCreate event enter:
 
In the FormCreate event enter:
  
 +
<syntaxhighlight>
 
  cbSymbols.Items.Clear;
 
  cbSymbols.Items.Clear;
 
  For I := 0 To 5 Do
 
  For I := 0 To 5 Do
 
   cbSymbols.Items.Add('');
 
   cbSymbols.Items.Add('');
 
  cbSymbols.ItemIndex := 0;  
 
  cbSymbols.ItemIndex := 0;  
 +
</syntaxhighligh>
  
 
This will write 6 blank entries, and select the first.
 
This will write 6 blank entries, and select the first.
Line 32: Line 29:
 
In the OnDrawItem event for cbSymbols place the following code:
 
In the OnDrawItem event for cbSymbols place the following code:
  
Procedure TMyForm.cbSymbolsDrawItem(Control: TWinControl;
+
<syntaxhighlight>
  Index: Integer; ARect: TRect; State: TOwnerDrawState);
+
procedure TMyForm.cbSymbolsDrawItem(  
var
+
  Control: TWinControl;
  cnv: TCanvas;
+
  Index: Integer;  
begin
+
  ARect: TRect;  
  if not (Control is TComboBox) then Exit;
+
  State: TOwnerDrawState );
  cnv:=TComboBox(Control).Canvas;
+
var
  Imagelist1.Draw(cnv, ARect.Left+2, Arect.Top+2, index);
+
  cnv: TCanvas;
End;
+
begin
 +
  if not (Control is TComboBox) then exit;
 +
  cnv := TComboBox(Control).Canvas;
 +
  Imagelist1.Draw( cnv, ARect.Left+2, Arect.Top+2, Index );
 +
end;
 +
</syntaxhighlight>
  
The adjustments (+2) are to centre the image in the item, if necessary.
+
The adjustments (+2) are to center the image in the item, if necessary.
  
 
[[File:combo.png]]
 
[[File:combo.png]]
  
 +
== See also ==
 +
* [[doc:lcl//controls/timagelist.html|TImageList doc]]
 +
* [[TImage]]
  
{{LCL Components Footer|THeaderControl|TPopupNotifier}}
 
 
{{LCL Components}}
 
{{LCL Components}}
  

Revision as of 11:21, 18 July 2016

TImageList timagelist.png is a component that provides a list of images that can be used within other components like TToolBar of TActionList.

Example with ComboBox

To use TImageList, drop an TImageList object onto the form. In this example we need six images.

All images must be the same size. If two sizes of image are to be used, then two TImageLists must be used.

Set the height and width of the images in the Object Inspector; In this case 50px wide by 18px high.

Set Style to csOwnerDrawFixed.

Double-click on the TImageList icon to open the TImageList editor. Make sure that the icons show correctly when selected. If they are smaller than expected, check the size in the Object Inspector <F11>. You may have to reload the images.

ImageListEd.png

Place a ComboBox on the form and name it cbSymbols.

In the FormCreate event enter:

 cbSymbols.Items.Clear;
 For I := 0 To 5 Do
   cbSymbols.Items.Add('');
 cbSymbols.ItemIndex := 0; 
</syntaxhighligh>

This will write 6 blank entries, and select the first.

In the OnDrawItem event for cbSymbols place the following code:

<syntaxhighlight>
procedure TMyForm.cbSymbolsDrawItem( 
  Control: TWinControl;
  Index: Integer; 
  ARect: TRect; 
  State: TOwnerDrawState );
var
  cnv: TCanvas;
begin
  if not (Control is TComboBox) then exit;
  cnv := TComboBox(Control).Canvas;
  Imagelist1.Draw( cnv, ARect.Left+2, Arect.Top+2, Index );
end;

The adjustments (+2) are to center the image in the item, if necessary.

combo.png

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 • TIpHtmlDataProvider • TIpHttpDataProvider • TIpHtmlPanel
Virtual Controls TVirtualDrawTree • TVirtualStringTree • TVTHeaderPopupMenu