Link to home
Start Free TrialLog in
Avatar of martbase
martbase

asked on

PageScroller Button Panel

Hi!

I am developing a program which creates buttons (TBitBtn) dynamically and uses a PageScroller as the display panel. My problem is that the PageScroller doesn't display its scroll buttons even when the number of buttons exceeds the display area. I have tried putting a PageControl, ScrollBox, then a Panel on the PageScroller and setting the Parent property of the buttons to the PageControl/ScrollBox/Panel; tried using the PageScroller by itself and setting the Parent property of the buttons to the PageScroller, but still I haven’t achieved the result I want. I really want to use the PageScroller as my button panel and I believe if it is possible in Delphi (Component palette) then I could do the same. I will appreciate any ideas, examples or articles that could enable me use the PageScroller to display my buttons and be able to scroll to those not visible on the screen.

Thank you,

Martin
ASKER CERTIFIED SOLUTION
Avatar of calinutz
calinutz
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
By the way.. you have an unfinished question... you should finish that too
https://www.experts-exchange.com/questions/22007174/Delphi-PageScroller-Query.html

Regards
Also take a look at thei free component:
http://www.torry.net/vcl/panels/enhancedpanels/scpanel.zip

and other panel components you can find on torry.net. They are quite usefull sometimes.

:-)
If you really want it to look like the delphi component pallette just use the following code:
//dfm

object Form1: TForm1
  Left = 192
  Top = 107
  Width = 979
  Height = 307
  Caption = 'Form1'
  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 ScrollBox2: TScrollBox
    Left = 0
    Top = 0
    Width = 971
    Height = 57
    HorzScrollBar.ButtonSize = 10
    HorzScrollBar.Margin = 5
    HorzScrollBar.Smooth = True
    HorzScrollBar.Size = 10
    HorzScrollBar.Style = ssHotTrack
    HorzScrollBar.Tracking = True
    HorzScrollBar.Visible = False
    VertScrollBar.Smooth = True
    VertScrollBar.Style = ssFlat
    VertScrollBar.Visible = False
    Align = alTop
    BevelInner = bvNone
    BevelOuter = bvNone
    BorderStyle = bsNone
    Ctl3D = False
    ParentBackground = True
    ParentCtl3D = False
    TabOrder = 0
  end
  object Button1: TButton
    Left = 0
    Top = 64
    Width = 117
    Height = 25
    Caption = 'Generate buttons'
    TabOrder = 1
    OnClick = Button1Click
  end
  object UpDown1: TUpDown
    Left = 934
    Top = -1
    Width = 37
    Height = 16
    Orientation = udHorizontal
    TabOrder = 2
    OnClick = UpDown1Click
  end
end
And the PAS code:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, jpeg, ExtCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    ScrollBox2: TScrollBox;
    Button1: TButton;
    UpDown1: TUpDown;
    procedure Button1Click(Sender: TObject);
    procedure UpDown1Click(Sender: TObject; Button: TUDBtnType);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
 bt:TBitBtn;
 i,j:Integer;
begin
  j:=10;
for i:=1 to 20 do
begin
bt:=TBitBtn.Create(Self);
bt.Parent:=ScrollBox2;
bt.Name:='but'+IntToStr(i);
bt.Caption:=bt.Name;
bt.Height:=22;
bt.Width:=80;
bt.top:=15;
bt.Left:=j;
j:=j+90;
end;
end;

procedure TForm1.UpDown1Click(Sender: TObject; Button: TUDBtnType);
begin
If Button=btNext then ScrollBox2.ScrollBy(-15,0)
else
If Button=btPrev then ScrollBox2.ScrollBy(15,0);
end;

end.
I assume you are still working on the code I gave you for the previous question... so :
- the upDown component should be parented by the tabsheet
- on the tabsheet you should place the scrollbox
- alClient the scrollbox (to align it to the tabsheet)

Of course Make Visible=false for the ScrollBox's  VertScrollBar and HorzScrollBar properties, make it flat ( ctl3d=false, borderstyle=none, and no bevels)

It should be done

regards
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well... dear martbase does my code work or do I waste my time answering your questions...?
Avatar of martbase
martbase

ASKER

Hi,

The code works but none uses the PageScroller. Maybe am the one who is wrong here but what component was used on the Delphi component palette. I like the way the scroll arrows appear when there are more buttons than can fit on a line.
Are you sure that you have tested the code? Or do you need the full working code again?
The above code does not use the pagescroller but it creates a behaviour just like the component pallete from Delphi. Except for the pagescroller thing... that cxan also be simulated in the ScrollBox. As you can read in the delphi help :

"...The page scroller control is similar to the scroll box control. However, the page scroller provides arrows that extend over the edges of the display area, whereas the scroll box provides scroll bars. Also, the page scroller supports scrolling for only one orientation (horizontal or vertical), so the constrained window must fit either the width or height of the display area."

So you can simulate it's behaviour just by adding a SpeedButton (with some special character on it or even a glyph that will look like the arrow of the PageScroller and use the same events like above I explained for the UpDown Buttons. You don't HAVE to use the updown buttons you can use whatever you like.


There is no component on the delphi pallete that is exactly like the component pallete. Borland created the component for themselves and did not share it with us. So all you can do is improvise it's look and behaviour, like I have shown you above.

Regards
I am sure a button like this will do just fine for simulating the appearance of the PageScroller button:

        object SpeedButton4: TSpeedButton
          Left = 838
          Top = 0
          Width = 14
          Height = 35
          Anchors = [akTop, akRight]
          Flat = True
          Glyph.Data = {
            B6010000424DB60100000000000036000000280000000A0000000C0000000100
            1800000000008001000000000000000000000000000000000000FFFFFFFFFFFF
            FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF
            FFFFFFFFFFFF000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF
            FFFFFFFFFFFF000000000000FFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF
            FFFFFFFFFFFF000000000000FFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF
            FFFFFFFFFFFF000000000000000000FFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF
            FFFFFFFFFFFF000000000000000000000000FFFFFFFFFFFF0000FFFFFFFFFFFF
            FFFFFFFFFFFF000000000000000000FFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF
            FFFFFFFFFFFF000000000000FFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF
            FFFFFFFFFFFF000000000000FFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF
            FFFFFFFFFFFF000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF
            FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF
            FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000}
          OnClick = SpeedButton4Click
        end
Now...
You must do the following:
in the PageControl... in the tab where the button (for adding shortcuts) is...you must set the scrollbox to have align = alNone. You then must shrink it's width a little just enough to allow placing a slim button in front of it and at the end of it. Then with Anchors you must anchor scrollbox to left and right side of the TabSheet.

Then place the slim speedbuttons on the TAB (not on the scrollbox). Set the right speedbutton to anchor to the right instead of left.
And after that just add events to the speedbuttons, such as:

For the speed button in the right side of the screen add this code
ScrollBox2.ScrollBy(-15,0)
For the speed button in the left side of the screen add this code
ScrollBox2.ScrollBy(15,0);


And that's all.
I repeat : there is no such component out there that is only one and does all that the component pallete does, so you have to improvize.

Regards
To only scroll when controls are on the scrollbox and only if thewy are too many to fit use this code in the right speedbuttonclick:

var i, max : Integer;

begin
  if scrollbox1.ControlCount > 0 then      // only if controls available
  begin
    max := scrollbox1.Controls[0].Left + scrollbox1.Controls[0].Width;
    For I := 0 to scrollbox1.ControlCount - 1 do
      if scrollbox1.Controls[I].Left  + scrollbox1.Controls[I].Width > max then
      begin
        max := scrollbox1.Controls[I].Left + scrollbox1.Controls[I].Width;
      end;
    if max > ScrollBox1.ClientWidth then
    begin
      ScrollBox1.ScrollBy(-10,0);
    end;
  end;
end;
Here is some code to show you how (it needs somt tunning but it works just fine doing what you expect it to do:
dfm file:
object Form1: TForm1
  Left = 192
  Top = 107
  BorderStyle = bsNone
  Caption = 'Shortcuts TAB'
  ClientHeight = 66
  ClientWidth = 862
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnClose = FormClose
  OnShow = FormShow
  PixelsPerInch = 96
  TextHeight = 13
  object Image1: TImage
    Left = 8
    Top = 60
    Width = 21
    Height = 21
    Transparent = True
    Visible = False
  end
  object Image2: TImage
    Left = 8
    Top = 108
    Width = 29
    Height = 25
    Picture.Data = {
      07544269746D6170F6060000424DF60600000000000036000000280000001800
      0000180000000100180000000000C0060000120B0000120B0000000000000000
      0000FF00FF0481BF0082C10082C1FF00FFFF00FFFF00FFFF00FFFF00FFFF00FF
      FF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00
      FFFF00FFFF00FFFF00FF0082C169BBDE75D0F329A3DD0082C10082C10082C100
      82C10082C1FF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FF
      FF00FFFF00FFFF00FFFF00FFFF00FFFF00FF0082C1219ACEB1E7FB56CBFA5DCC
      FA5CCBF854C5F333ABE228A3D90082C10082C10082C10082C10082C1FF00FFFF
      00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FF0082C10386C2
      9AD8ED66CFF855C7F658C7F659CAF65CCBF75ECEFA5ECCFA59C7F64EC0EF2DA6
      DD229CD50082C10082C10082C10082C1FF00FFFF00FFFF00FFFF00FFFF00FFFF
      00FF0082C124ADE134A5D397E1FB52C6F657C7F657C7F657C7F657C7F658C7F6
      58C9F65CCBF75ECCFA5FCEFA5DCBF858C9F435ADE32CA5DC0082C1FF00FFFF00
      FFFF00FFFF00FFFF00FF0082C144C6F30C8CC6BCEBFA57CBF75ACBF65ACBF65A
      CBF65ACBF65ACBF65ACBF65ACBF65ACBF65BCBF65BCBF65DCEF662CFF844BBED
      5AC7F20082C1FF00FFFF00FFFF00FFFF00FF0082C149CCF70082C18BD3EB7EDC
      FB5DD0F660D0F660D0F660D0F660D0F660D0F660D0F660D0F660D0F65FD0F65F
      D0F760D1F741BAE968D4F80082C1FF00FFFF00FFFF00FFFF00FF0082C14BCEF8
      2AA4D71C97CCADEDFC60D3F666D5F666D5F666D5F666D5F666D5F666D5F666D5
      F666D5F666D5F666D7F767D7F744BDE777E1FA51C2E90082C1FF00FFFF00FFFF
      00FF0082C14DCFFC44B1E10284C2C2F0FB6EDDF86ADAF76BDCF76BDCF76BDCF7
      6BDCF76ADCF76ADCF76ADCF76ADCF76BDCF76BDDF848C2E77AE5FA6DDAF40082
      C1FF00FFFF00FFFF00FF0082C14FD3FF48B4E60082C179CCE79EEFFC6AE0F76D
      E0F76DE0F76EE0F76EE0F76FE1F76FE1F76FE1F76FE1F76FE2F770E2F84DC7E9
      7DE7FA81EDFB0082C1FF00FFFF00FFFF00FF0082C157D5FF4CB7EB2CA6DC088A
      C5C9F6FC7FEBFB7DEAFA7DEAFA79EAFA76E7F873E5F874E6F874E6F874E6F875
      E6F876E7F852CEE981EEF88AF4FC68D9EE0082C1FF00FFFF00FF0082C175DDFF
      4FBAEF49B5EB0082C1ADE0F0C0EDF7BDEEF7C1F0F8C2F3FA8EEEF884EFFA7BEB
      F87DEAF87DEBF87DEBF87EEDFA59D3E989F3FA8FF7FB89F2FA0082C1FF00FFFF
      00FF0082C193E5FF52BDF44FBAF24DB6EF36A7E10082C10082C10082C10082C1
      7BCBE7BAF0F8A6F6FC95EFFA91EEF892EEF895EFFA6ED5E9A5F6FAA4F6FAB1FE
      FE0082C1FF00FFFF00FF0082C1A6EFFF5AC6F456C2F256C2F356C1F253BFF054
      BFF054C0F031AAE00284C22EA3D1CAEFF7CAF7FCBDF4FEB6F3FBB5F3FB8BD8EB
      C9FAFBC7FAFAD8FFFEA5E7F20082C1FF00FF0082C1A7F0FF63CFF65ECBF35ECB
      F35ECBF35ECBF25ECBF25ECBF25DCBF25CC9F232ACE0098BC687CFE7D3F2F8CC
      F4FBC9F4FCA3DDEDF2FFFFF0FFFEFAFFFFF6FFFF0082C1FF00FF0082C1B2F6FF
      6AD8F666D4F366D4F366D4F366D4F366D4F366D4F366D4F366D4F365D3F33CB7
      E30082C11693CA86CEE9B0E1F097D1E7CEEAF4CFEAF3D4EDF4E0F0F70082C1FF
      00FF0082C1B4F8FF72E0F76DDCF46DDCF46DDCF46DDCF46DDCF66DDCF46BDCF4
      6BDCF46CDCF46CDAF469D8F335B1DC0082C10082C10082C10082C10082C10082
      C10082C10082C1FF00FF0082C1CAFFFF76E7F876E3F776E3F776E3F776E3F775
      E3F679E7F87EEBFB7BEBFA7AEAFA79E9F877E9F876E6F877E7F780EEFB0082C1
      FF00FFFF00FFFF00FFFF00FFFF00FFFF00FF0082C1D8FEFF95F7FC75EAF77AED
      F77AEDF77AEDF77DEDF789EBF69FE7F4A0EBF6A3EDF7A5EFF7A4F0F89DF0FA96
      F0FB95F8FF0082C1FF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FF0082C1
      D0FFFF8EFAFC89F8FB86F6FA84F6FB83F3F85CC4E00082C10082C10082C10082
      C10082C10082C10082C10082C10082C1FF00FFFF00FFFF00FFFF00FFFF00FFFF
      00FFFF00FFFF00FF0082C1AAEAF3A6EBF3AAEEF6B1F7FA9DEAF30082C1FF00FF
      FF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00
      FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FF0082C10082C10082C10082C100
      82C1FF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FF
      FF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00
      FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF
      00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FF
      FF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00
      FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF
      00FF}
    Visible = False
  end
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 862
    Height = 66
    Align = alClient
    TabOrder = 0
    object PageControl1: TPageControl
      Left = 1
      Top = 1
      Width = 860
      Height = 64
      ActivePage = TabSheet1
      Align = alClient
      PopupMenu = PopupMenu1
      TabOrder = 0
      object TabSheet1: TTabSheet
        Caption = 'File shortcuts'
        DesignSize = (
          852
          36)
        object Label1: TLabel
          Left = 4
          Top = 12
          Width = 6
          Height = 13
          Caption = '1'
          Visible = False
        end
        object SpeedButton3: TSpeedButton
          Left = 2
          Top = 0
          Width = 11
          Height = 35
          Caption = '<'
          OnClick = SpeedButton3Click
        end
        object SpeedButton4: TSpeedButton
          Left = 838
          Top = 0
          Width = 14
          Height = 35
          Anchors = [akTop, akRight]
          Flat = True
          Glyph.Data = {
            B6010000424DB60100000000000036000000280000000A0000000C0000000100
            1800000000008001000000000000000000000000000000000000FFFFFFFFFFFF
            FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF
            FFFFFFFFFFFF000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF
            FFFFFFFFFFFF000000000000FFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF
            FFFFFFFFFFFF000000000000FFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF
            FFFFFFFFFFFF000000000000000000FFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF
            FFFFFFFFFFFF000000000000000000000000FFFFFFFFFFFF0000FFFFFFFFFFFF
            FFFFFFFFFFFF000000000000000000FFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF
            FFFFFFFFFFFF000000000000FFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF
            FFFFFFFFFFFF000000000000FFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF
            FFFFFFFFFFFF000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF
            FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFF
            FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000}
          OnClick = SpeedButton4Click
          OnMouseDown = SpeedButton4MouseDown
          OnMouseUp = SpeedButton4MouseUp
        end
        object ScrollBox1: TScrollBox
          Left = 14
          Top = 0
          Width = 824
          Height = 35
          HorzScrollBar.Visible = False
          VertScrollBar.Visible = False
          Anchors = [akLeft, akTop, akRight]
          BevelInner = bvNone
          BevelOuter = bvNone
          BorderStyle = bsNone
          Ctl3D = False
          ParentCtl3D = False
          TabOrder = 0
          object SpeedButton1: TSpeedButton
            Left = 16
            Top = 1
            Width = 30
            Height = 27
            Hint = 'Add new shortcut'
            Flat = True
            Glyph.Data = {
              36030000424D3603000000000000360000002800000010000000100000000100
              18000000000000030000120B0000120B00000000000000000000FF00FFFF00FF
              FF00FFFF00FFFF00FF8E5D598E5D598E5D598E5D598E5D598E5D598E5D598E5D
              598E5D59734241FF00FFFF00FFFF00FFFF00FFFF00FFFF00FF92625AFEDDBCFF
              D9B4FFD5ACFFD1A5FFCE9DFECA97FFC790FFC48B734241FF00FFFF00FFFF00FF
              FF00FFFF00FFFF00FF98665DFFE3C7DD903DDD903DDD903DDD903DDD903DDD90
              3DFFC792734241FF00FFFF00FFFF00FFFF00FFFF00FFFF00FFA06C5FFEE9D3FF
              E5CAFFE1C1FFDCBAFED8B1FED3A9FFD0A1FFCC9A734241FF00FF8E5D598E5D59
              8E5D598E5D598E5D59A77463FEEEDDDD903DDD903DDD903DDD903DDD903DDD90
              3DFED1A4734241FF00FF92625AFEDDBCFFD9B4FFD5ACFFD1A5B17D67FEF3E6FE
              EFDEFEEAD8FFE7CFFEE2C7FEDEBDFFD9B6FED5AD734241FF00FF98665DFFE3C7
              DD903DDD903DDD903DBB8369FFF7EFDD903DDD903DDD903DDD903DDD903DDD90
              3DFEDAB8734241FF00FFA06C5FFEE9D3FFE5CAFFE1C1FFDCBAC48B6CFEFAF7FE
              F7F0FEF4EAFEF2E3FEEDDCFEE9D4FEE5CBFEE1C2734241FF00FFA77463FEEEDD
              DD903DDD903DDD903DCC9370FEFEFCFEFBF8FEF8F3FEF6EDFEF2E6E5D5D0C6B1
              AFA79395734241FF00FFB17D67FEF3E6FEEFDEFEEAD8FFE7CFD59C74FEFEFEFE
              FEFEFEFBFAFEFAF4FEF6EEA0675BA0675BA0675B9D6559FF00FFBB8369FFF7EF
              DD903DDD903DDD903DDCA175FEFEFEFEFEFEFEFEFEFEFCFBFEFAF6A0675BE5A1
              54DC832AFF00FFFF00FFC48B6CFEFAF7FEF7F0FEF4EAFEF2E3E1A577D1926DD1
              926DD1926DD1926DD1926DA0675BEB9E43FF00FFFF00FFFF00FFCC9370FEFEFC
              FEFBF8FEF8F3FEF6EDFEF2E6E5D5D0C6B1AFA79395734241FF00FFFF00FFFF00
              FFFF00FFFF00FFFF00FFD59C74FEFEFEFEFEFEFEFBFAFEFAF4FEF6EEA0675BA0
              675BA0675B9D6559FF00FFFF00FFFF00FFFF00FFFF00FFFF00FFDCA175FEFEFE
              FEFEFEFEFEFEFEFCFBFEFAF6A0675BE5A154DC832AFF00FFFF00FFFF00FFFF00
              FFFF00FFFF00FFFF00FFE1A577D1926DD1926DD1926DD1926DD1926DA0675BEB
              9E43FF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FF}
            ParentShowHint = False
            ShowHint = True
            OnClick = SpeedButton1Click
          end
        end
      end
    end
  end
  object OpenDialog1: TOpenDialog
    Left = 128
    Top = 24
  end
  object PopupMenu1: TPopupMenu
    Left = 684
    Top = 4
    object CloseTAB1: TMenuItem
      Caption = 'Close TAB'
      OnClick = CloseTAB1Click
    end
  end
  object Timer1: TTimer
    Enabled = False
    Interval = 500
    OnTimer = Timer1Timer
    Left = 296
    Top = 24
  end
end
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, ComCtrls, StdCtrls, SHELLAPI, ExtCtrls, ShlObj, ActiveX,
  Menus, ImgList, COMObj, commctrl;

type
  TForm1 = class(TForm)
    OpenDialog1: TOpenDialog;
    Image1: TImage;
    Image2: TImage;
    Panel1: TPanel;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    Label1: TLabel;
    PopupMenu1: TPopupMenu;
    CloseTAB1: TMenuItem;
    ScrollBox1: TScrollBox;
    SpeedButton1: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    Timer1: TTimer;
    procedure SpeedButton1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure CloseTAB1Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure SpeedButton4MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SpeedButton4MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SpeedButton4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.SpeedButton1Click(Sender: TObject);
var
   sp:TSpeedButton;
   filename:string;
   i:integer;
  Info : TSHFileInfo;
  InfoSize : Integer;
  BitMap:TBitMap;

// pentru lnk files

    descr,s1,s2 : string;
    pidl                   : PItemIDList;
    findData               : TWin32FindData;
    iconPath               : string;
    workingDir             : string;
    hotKey                 : string;
    showCmd                : integer;

begin

if OpenDialog1.Execute then
  begin
   filename := OpenDialog1.FileName;
   sp:=TSpeedButton.Create(self);
   sp.Parent:=ScrollBox1;
   sp.Name:='btn'+Label1.Caption;
   sp.ShowHint:=True;
  InfoSize := SizeOf(TSHFileInfo);
  FillChar(Info, InfoSize, 0);
  SHGetFileInfo(PChar(filename), 0, Info, InfoSize, SHGFI_ICON or SHGFI_SMALLICON);
  Image1.Picture.icon.Handle := Info.hIcon;
  Image1.Picture.Icon.SaveToFile('c:\pic.ico');
   Bitmap := TBitmap.Create;
   Bitmap.Width := Image1.Picture.icon.Width-16;
   Bitmap.Height := Image1.Picture.icon.Height-16;
   BitMap.TransparentColor:=clWhite;
   BitMap.Transparent:=true;
   Bitmap.Canvas.Draw(0, 0, Image1.Picture.icon);
   Bitmap.SaveToFile('c:\pic.bmp'); //Convert ICO to BMP!
   Bitmap.Free;
   sp.Glyph.LoadFromFile('c:\pic.bmp');
   sp.Hint:=filename;
   sp.Flat:=true;
   sp.Top:=1;
   sp.Height:=27;
//   sp.OnClick:=myOnClickEvent;
   sp.Width:=30;
   sp.Left:=16+StrToInt(Label1.Caption)*30;
   sp.Refresh;
   Label1.Caption:=IntToStr(StrToInt(Label1.Caption)+1);
  end;
end;

// ***********************************************************************

procedure TForm1.SpeedButton3Click(Sender: TObject);
var
  i, Min : Integer;
begin
  if scrollbox1.ControlCount > 0 then      // only if controls available
  begin
    min := scrollbox1.Controls[0].Left;
    For I := 0 to scrollbox1.ControlCount - 1 do
      if scrollbox1.Controls[I].Left < min then
      begin
        min := scrollbox1.Controls[I].Left;
      end;
    if min < 0 then
    begin
      ScrollBox1.ScrollBy(10,0);
    end;
  end;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
//ShowMessage('TODO save of the buttons in an ini file and retrieve them upon startup of the application');
end;

procedure TForm1.FormShow(Sender: TObject);
begin
Form1.Align:=alTop;
end;

procedure TForm1.CloseTAB1Click(Sender: TObject);
begin
PageControl1.ActivePage.Destroy;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var i, max : Integer;
begin
  if scrollbox1.ControlCount > 0 then      // only if controls available
  begin
    max := scrollbox1.Controls[0].Left + scrollbox1.Controls[0].Width;
    For I := 0 to scrollbox1.ControlCount - 1 do
      if scrollbox1.Controls[I].Left  + scrollbox1.Controls[I].Width > max then
      begin
        max := scrollbox1.Controls[I].Left + scrollbox1.Controls[I].Width;
      end;
    if max > ScrollBox1.ClientWidth then
    begin
      ScrollBox1.ScrollBy(-10,0);
    end;
  end;
end;

procedure TForm1.SpeedButton4MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
Timer1.Enabled:=True;
end;

procedure TForm1.SpeedButton4MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
Timer1.Enabled:=False;
end;

procedure TForm1.SpeedButton4Click(Sender: TObject);
var i, max : Integer;
begin
  if scrollbox1.ControlCount > 0 then      // only if controls available
  begin
    max := scrollbox1.Controls[0].Left + scrollbox1.Controls[0].Width;
    For I := 0 to scrollbox1.ControlCount - 1 do
      if scrollbox1.Controls[I].Left  + scrollbox1.Controls[I].Width > max then
      begin
        max := scrollbox1.Controls[I].Left + scrollbox1.Controls[I].Width;
      end;
    if max > ScrollBox1.ClientWidth then
    begin
      ScrollBox1.ScrollBy(-10,0);
    end;
  end;
end;

end.
Forced accept.

Computer101
EE Admin