Scroll Buttons on a Panel Up and Down (Very Urgent)

Hello Experts,

  I have a Panel on which I need to place 20 buttons. I also have 2 buttons Up and Down. I will be able to view only 10 buttons on the Panel at a time. Now when I press the Up Button, I should be able to Scroll Up one button and similarly when I press Down I should be able to scroll Down one button. I am not supposed to use a Scroll Bar. I should be able to scroll using the Up and Down buttons only. Similarly I should be able to move Left and Right (Horizontal Scrolling). How will I be able to do this. Any ideas appreciated.

with regards,
padmaja.
LVL 6
saravananvgAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Eddie ShipmanConnect With a Mentor All-around developerCommented:
No, you need to put a TStrollBox on your panel and make it alLeft aligned. Drop your
buttons on top of the TStcrollBox and your "scroll" buttons on the right
and everything should take care of itself.


unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    ScrollBox1: TScrollBox;
    btnUp: TButton;
    btnDown: TButton;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    Button10: TButton;
    Button11: TButton;
    Button12: TButton;
    Button13: TButton;
    Button14: TButton;
    Button15: TButton;
    Button16: TButton;
    Button17: TButton;
    Button18: TButton;
    Button19: TButton;
    Button20: TButton;
    procedure btnUpClick(Sender: TObject);
    procedure btnDownClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btnUpClick(Sender: TObject);
begin
  if Button1.Top < 0 then
    ScrollBox1.ScrollBy(0, ScrollBox1.Height);
end;

procedure TForm1.btnDownClick(Sender: TObject);
begin
  if Button1.Top >= 0 then
    ScrollBox1.ScrollBy(0, -ScrollBox1.Height);
end;

end.


DFM Source:
object Form1: TForm1
  Left = 282
  Top = 62
  Width = 696
  Height = 483
  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 Panel1: TPanel
    Left = 0
    Top = 0
    Width = 642
    Height = 449
    Align = alLeft
    BevelOuter = bvNone
    Caption = 'Panel1'
    TabOrder = 0
    object Panel2: TPanel
      Left = 529
      Top = 0
      Width = 113
      Height = 449
      Align = alRight
      BevelOuter = bvNone
      TabOrder = 0
      object btnUp: TButton
        Left = 11
        Top = 35
        Width = 75
        Height = 25
        Caption = 'Up'
        TabOrder = 0
        OnClick = btnUpClick
      end
      object btnDown: TButton
        Left = 11
        Top = 60
        Width = 75
        Height = 25
        Caption = 'Down'
        TabOrder = 1
        OnClick = btnDownClick
      end
    end
    object Panel3: TPanel
      Left = 0
      Top = 0
      Width = 529
      Height = 449
      Align = alClient
      BevelOuter = bvNone
      Caption = 'Panel3'
      TabOrder = 1
      object ScrollBox1: TScrollBox
        Left = 0
        Top = 0
        Width = 529
        Height = 449
        HorzScrollBar.Visible = False
        VertScrollBar.Visible = False
        Align = alClient
        BevelInner = bvNone
        BevelOuter = bvNone
        TabOrder = 0
        object Button1: TButton
          Left = 0
          Top = 0
          Width = 105
          Height = 223
          Caption = 'Button1'
          TabOrder = 0
        end
        object Button2: TButton
          Left = 105
          Top = 0
          Width = 105
          Height = 223
          Caption = 'Button2'
          TabOrder = 1
        end
        object Button3: TButton
          Left = 210
          Top = 0
          Width = 105
          Height = 223
          Caption = 'Button3'
          TabOrder = 2
        end
        object Button4: TButton
          Left = 315
          Top = 0
          Width = 105
          Height = 223
          Caption = 'Button4'
          TabOrder = 3
        end
        object Button5: TButton
          Left = 420
          Top = 0
          Width = 105
          Height = 223
          Caption = 'Button5'
          TabOrder = 4
        end
        object Button6: TButton
          Left = 0
          Top = 223
          Width = 105
          Height = 223
          Caption = 'Button6'
          TabOrder = 5
        end
        object Button7: TButton
          Left = 105
          Top = 223
          Width = 105
          Height = 223
          Caption = 'Button7'
          TabOrder = 6
        end
        object Button8: TButton
          Left = 210
          Top = 223
          Width = 105
          Height = 223
          Caption = 'Button8'
          TabOrder = 7
        end
        object Button9: TButton
          Left = 315
          Top = 223
          Width = 105
          Height = 223
          Caption = 'Button9'
          TabOrder = 8
        end
        object Button10: TButton
          Left = 420
          Top = 223
          Width = 105
          Height = 223
          Caption = 'Button10'
          TabOrder = 9
        end
        object Button11: TButton
          Left = 0
          Top = 446
          Width = 105
          Height = 223
          Caption = 'Button11'
          TabOrder = 10
        end
        object Button16: TButton
          Left = 0
          Top = 670
          Width = 105
          Height = 223
          Caption = 'Button16'
          TabOrder = 11
        end
        object Button17: TButton
          Left = 105
          Top = 670
          Width = 105
          Height = 223
          Caption = 'Button17'
          TabOrder = 12
        end
        object Button12: TButton
          Left = 105
          Top = 447
          Width = 105
          Height = 223
          Caption = 'Button12'
          TabOrder = 13
        end
        object Button13: TButton
          Left = 210
          Top = 447
          Width = 105
          Height = 223
          Caption = 'Button13'
          TabOrder = 14
        end
        object Button18: TButton
          Left = 210
          Top = 670
          Width = 105
          Height = 223
          Caption = 'Button18'
          TabOrder = 15
        end
        object Button19: TButton
          Left = 315
          Top = 670
          Width = 105
          Height = 223
          Caption = 'Button19'
          TabOrder = 16
        end
        object Button14: TButton
          Left = 315
          Top = 447
          Width = 105
          Height = 223
          Caption = 'Button14'
          TabOrder = 17
        end
        object Button15: TButton
          Left = 420
          Top = 447
          Width = 105
          Height = 223
          Caption = 'Button15'
          TabOrder = 18
        end
        object Button20: TButton
          Left = 420
          Top = 670
          Width = 105
          Height = 223
          Caption = 'Button20'
          TabOrder = 19
        end
      end
    end
  end
end

0
 
SergiuAdrianCommented:
how about moving al the bunttons <up> when you click the <up button> and <down> when pressing <down button>:

when press up:

for i:= 1 to buttonCount do
   button[i].top := button[i].top - ScrollDistance;

when press down (the only diference is you have to add the moving distance):

for i:= 1 to buttonCount do
   button[i].top := button[i].top + ScrollDistance;

if you make all buttons same size and the distance between button rows and edge/bottom of the pannel  is same you can find the ScrollDistance := TheHeightOfAButton + DistanceBetweenRows. this will make the first row disapear when click up and the last row disapear when click down.

i sugest also to verify when all rows will be invisible if click up or down. this means you have scroll to much up or to much down. but this is optional ;)
0
 
Hamidreza VakilianSenior iOS DeveloperCommented:
Hi!

It's very simple...

assume that P1 is the main panel that you have to scroll within it. you can easily put another Panel in P1 & put your buttons on the second panel...

For scrolling you can change TOP & LEFT properties of the second panel....
Also these properties accept negative values....

Programmer-x
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
SergiuAdrianCommented:
yes, if you use only 2 rows of buttons this is a good idea.
0
 
SergiuAdrianCommented:
or if use more rows also you can make a panel for each row an move all panels at the same time.
0
 
kenpemCommented:
or split the buttons between two panels which appear in the same place on the form. Then as Up/Down is pushed, set Panel1.Visible, etc.
0
 
saravananvgAuthor Commented:
Hello Experts,

  Thanks for your suggesstions, I shall work on them and get back to you very soon.

with regards,
padmaja.
0
All Courses

From novice to tech pro — start learning today.