ButtonBar

georgepatotk

Contributor
Joined
Mar 1, 2004
Messages
432
Location
Malaysia
I don't know what is this control called, but, i need to do something similar with the picture i have shown.
What are the control that I could use in order to do this?
Thanks in advance.
 

Attachments

Code:
  Dim itemHeight as Integer = 60 ' can set to any size u want
  Dim itemWidht as Integer = 80 ' can set to any size u want

  Private Sub btnLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLeft.Click
        If pnlIn.Left - pnlIn.Width < 0 And pnlIn.Left < 0 Then
            pnlIn.Left = pnlIn.Left + itemWidth
        End If
    End Sub

    Private Sub btnRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRight.Click
        If pnlIn.Width - (0 - pnlIn.Left) > pnlOut.Width Then
            pnlIn.Left = pnlIn.Left - itemWidth
        End If
    End Sub

Private Sub AddButtons() ' add eleven buttons
        For i As Integer = 0 To 10
            Dim btn As New Button

            btn.Text = "btn" & i

            btn.Left = pnlIn.Controls.Count * itemWidth
            btn.Width = itemWidth
            btn.Height = itemHeight
            pnlIn.Width = (pnlIn.Controls.Count + 1) * itemWidth

            pnlIn.Controls.Add(btn)
        Next
End Sub

here is the workaround for the case. I created it my own. So, I think there must be an easier way to do this. Please guide. Thanks...
 

Attachments

You need a scrollable button control then? Why not just use a toolbar within a scrollable control or a series of buttons in a scrollable control?
 
An alternative could be to use a toolbar control where the first and last buttons are arrow buttons which hide/show middle buttons to create the effect of their scrolling.

Sorry if this is a bit long.
Code:
Imports System.Windows.Forms
 
Public Class Form1
    Inherits System.Windows.Forms.Form
 
    Public Shared Sub Main()
        Application.EnableVisualStyles()
        Application.Run(New Form1)
    End Sub
 
#Region " Windows Form Designer generated code "
 
    Public Sub New()
        MyBase.New()
 
        'This call is required by the Windows Form Designer.
        InitializeComponent()
 
        'Add any initialization after the InitializeComponent() call
    End Sub
 
    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
 
    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer
 
    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    Friend WithEvents ToolBar1 As System.Windows.Forms.ToolBar
    Friend WithEvents ToolBarButton1 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton2 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton3 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton4 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton5 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton6 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton7 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton8 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton9 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton10 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton11 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton12 As System.Windows.Forms.ToolBarButton
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.ToolBar1 = New System.Windows.Forms.ToolBar
        Me.ToolBarButton1 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton2 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton3 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton4 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton5 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton6 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton7 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton8 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton9 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton10 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton11 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton12 = New System.Windows.Forms.ToolBarButton
        Me.SuspendLayout()
   
        'ToolBar1
        Me.ToolBar1.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.ToolBarButton1,  _
Me.ToolBarButton2, Me.ToolBarButton3, Me.ToolBarButton4, _
Me.ToolBarButton5, Me.ToolBarButton6, Me.ToolBarButton7, _
Me.ToolBarButton8, Me.ToolBarButton9, Me.ToolBarButton10, _
Me.ToolBarButton11, Me.ToolBarButton12})
        Me.ToolBar1.DropDownArrows = True
        Me.ToolBar1.Location = New System.Drawing.Point(0, 0)
        Me.ToolBar1.Name = "ToolBar1"
        Me.ToolBar1.ShowToolTips = True
        Me.ToolBar1.Size = New System.Drawing.Size(360, 42)
        Me.ToolBar1.TabIndex = 0
 
        Me.ToolBarButton1.Text = "<"
        Me.ToolBarButton2.Text = "1"
        Me.ToolBarButton3.Text = "2"
        Me.ToolBarButton4.Text = "3"
        Me.ToolBarButton5.Text = "4"
        Me.ToolBarButton6.Text = "5"
        Me.ToolBarButton7.Text = "6"
        Me.ToolBarButton7.Visible = False
        Me.ToolBarButton8.Text = "7"
        Me.ToolBarButton8.Visible = False
        Me.ToolBarButton9.Text = "8"
        Me.ToolBarButton9.Visible = False
        Me.ToolBarButton10.Text = "9"
        Me.ToolBarButton10.Visible = False
        Me.ToolBarButton11.Text = "0"
        Me.ToolBarButton11.Visible = False
        Me.ToolBarButton12.Text = ">"
 
        'Form1
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(360, 374)
        Me.Controls.Add(Me.ToolBar1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)
 
    End Sub
 #End Region
 
    Dim FirstVisible As Integer = 1
    Dim LastVisible As Integer = 5
 
'This is where the scrolling is done. We hide the first/last button (depending
'on which way we scroll) update the "window" variables that specify the 
'visible range of buttons, then we show the new last/first button (depending
'on which way we scroll).
    Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal _
    e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
        With ToolBar1
            If e.Button Is .Buttons(0) AndAlso FirstVisible > 1 Then
                'If 'BACK BUTTON' and we are not at the left end of scrolling toolbar
 
                .Buttons(LastVisible).Visible = False
                FirstVisible -= 1
                LastVisible -= 1
                .Buttons(FirstVisible).Visible = True
            ElseIf e.Button Is ToolBar1.Buttons(ToolBar1.Buttons.Count - 1) AndAlso _
            LastVisible < .Buttons.Count - 2 Then
                'If 'FORWARD BUTTON' and we are not at end of scrolling toolbar 
 
                .Buttons(FirstVisible).Visible = False
                FirstVisible += 1
                LastVisible += 1
                .Buttons(LastVisible).Visible = True
            End If
        End With
    End Sub
End Class
 
Last edited:
Back
Top