Glyphs for Lazarus - part 2
Here's a slightly modified version of our project Glyph. Now, every image available in folder c:\lazarus\images\glyph is displayed
on its own speedbutton:
Project Glyph2
We dynamically create a speedbutton for each picture of c:\lazarus\images\glyph.
- Start a new Lazarus project and save it as Glyph2. Resize Form1 to a comfortable width and height (we used 500 x 620).
- Drop a TSpeedButton near the top-left of the form.
- Drop a TShellListView on the form. You find it under the tab "Misc".
Set its properties ViewStyle to vsList
- Add a TImage.
- Create an OnCreate event handler for Form1:
procedure TForm1.FormCreate(Sender: TObject);
var
i, BtnHeigth, BtnTop, NumberOfButtons: integer;
ImgFile: string; Btn: TSpeedButton;
begin
Image1.Visible := False;
ShellListView1.Visible := False;
ShellListView1.Root := 'c:\lazarus\images\glyph';
BtnTop := SpeedButton1.Top + SpeedButton1.Height + 4;
NumberOfButtons := ShellListView1.Items.Count;
for i := 1 to NumberOfButtons do begin
ImgFile := ShellListView1.Items[i - 1].Caption;
Image1.Picture.LoadFromFile(ShellListView1.Root + '\' + ImgFile);
if i > 1 then begin
Btn := TSpeedButton.Create(Form1);
Btn.Parent := Form1;
BtnHeigth := Image1.Picture.Bitmap.Height + 4;
if BtnHeigth < SpeedButton1.Height then
BtnHeigth := SpeedButton1.Height;
if BtnHeigth > 36 then
BtnHeigth := 36;
Btn.Height := BtnHeigth;
if i < 21 then
Btn.Left := SpeedButton1.Left
else
if i < 41 then
Btn.Left := SpeedButton1.Left + SpeedButton1.Width + 10
else
Btn.Left := SpeedButton1.Left + 2 * SpeedButton1.Width + 20;
if (i = 21) or (i = 41) then
BtnTop := SpeedButton1.Top;
Btn.Top := BtnTop;
Btn.Width := SpeedButton1.Width;
BtnTop := BtnTop + BtnHeigth + 5;
end
else
Btn := SpeedButton1;
Btn.Glyph := Image1.Picture.Bitmap;
Btn.Caption := ImgFile;
end;
end;
- Save your files and press F9.
|
|