Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleAdd and remove buttons from a scrolled button area
DescriptionThis example shows how to add and remove buttons from a scrolled button area in Visual Basic 6.
Keywordsbutton, add, remove, scroll
CategoriesControls
 
When the user clicks the Add button, the program uses Load to add a new button to the cmdButton control array. It sets the new button's Container so it is in the same PictureBox as the other buttons. It then calls subroutine SetScrollBar to adjust the buttons' scroll bar.
 
Private Sub cmdAdd_Click()
Dim new_index As Integer

    new_index = cmdButton.UBound + 1
    Load cmdButton(new_index)
    cmdButton(new_index).Move _
        cmdButton(new_index - 1).Left, _
        cmdButton(new_index - 1).Top + cmdButton(new_index _
            - 1).Height + 120
    cmdButton(new_index).Container = _
        cmdButton(new_index - 1).Container
    cmdButton(new_index).Visible = True
    cmdButton(new_index).Caption = "Button " & _
        Format$(new_index)

    SetScrollBar
End Sub

Private Sub SetScrollBar()
    ' Size the inner PictureBox.
    InnerPict.Height = cmdButton(cmdButton.UBound).Top + _
        cmdButton(cmdButton.UBound).Height + 120

    ' See if we need the scroll bar.
    If InnerPict.Height <= OuterPict.ScaleHeight Then
        InnerPict.Move 0, 0
        VBar.Visible = False
    Else
        ' Set scroll bar properties.
        VBar.Min = 0
        VBar.Max = OuterPict.ScaleHeight - InnerPict.Height
        VBar.LargeChange = OuterPict.ScaleHeight
        VBar.SmallChange = OuterPict.ScaleHeight / 5
        VBar.Visible = True
    End If
End Sub
 
When the user clicks the Remove button, the program unloads the most recently created button from the control array. It then calls subroutine SetScrollBar to adjust the buttons' scroll bar.
 
Private Sub cmdRemove_Click()
    If cmdButton.UBound < 1 Then Exit Sub

    Unload cmdButton(cmdButton.UBound)
    SetScrollBar
End Sub
 
Letting the user add and remove an arbitrary number of buttons
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated