Results 1 to 8 of 8

Thread: Is there a way to add a scroll bar to a list of command buttons?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Is there a way to add a scroll bar to a list of command buttons?

    Is there a way to add a scroll bar to a list of command buttons? OR is there a way to have a long list of items and you can scroll through them and then click on the one you want? Thanks guys.

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Is there a way to add a scroll bar to a list of command buttons?

    Listbox
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Is there a way to add a scroll bar to a list of command buttons?

    thanks, so if i had a list box full of things to click on, if i click on something on the list box, an textfile relating to that thing could open in a text box?
    I mean, what would be a simple code, to load a bunch of names from a textfile into the listbox.

    like
    OptionA
    OptionB
    OptionC
    etc..

    I've done it with splitting it up into 2 or 3 groups, but for a single word per line i forget how to do.
    Last edited by Justin M; Jan 29th, 2007 at 05:18 PM.

  4. #4
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: Is there a way to add a scroll bar to a list of command buttons?

    Load names from text file to listbox:
    VB Code:
    1. Dim TextFile As String
    2.   Dim Item As String
    3.  
    4.   TextFile = "MyFile.txt"
    5.   Open TextFile For Input As #1
    6.   Do Until EOF(1)
    7.     Line Input #1, Item
    8.     List1.AddItem Item
    9.   Loop
    10.   Close #1

  5. #5
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: Is there a way to add a scroll bar to a list of command buttons?

    Yes if you put the Command buttons on a PictureBox then scroll the PictureBox with the scrollbar. Do a search there are plenty of examples on here.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Is there a way to add a scroll bar to a list of command buttons?

    thanks i found something simular

    Quote Originally Posted by iPrank
    Add 3 command buttons, a HScrollbar a VScrollbar and a picturebox in the form.
    Rename the picturebox to picContainer
    Add another picturebox (Picture1) inside picContainer.
    Set Picture1's Borderstyle=None and Appearance=Flat.
    VB Code:
    1. Option Explicit
    2. Private Sub Command1_Click()
    3.   Picture1.Picture = LoadPicture("C:\SmallPic.jpg")
    4.   SetScrollBars
    5. End Sub
    6. '-----------------------------------------------------------------
    7. Private Sub Command2_Click()
    8.   Picture1.Picture = LoadPicture("C:\LargePic.jpg")
    9.   SetScrollBars
    10. End Sub
    11. '-----------------------------------------------------------------
    12. Private Sub Form_Load()
    13.   '[b]You can set these at designtime[/b]
    14.  
    15.   Me.ScaleMode = vbPixels
    16.   picContainer.ScaleMode = vbPixels
    17.   Picture1.ScaleMode = vbPixels
    18.  
    19.   HScroll1.Move picContainer.Left, _
    20.      picContainer.Top + picContainer.Height, _
    21.      picContainer.Width
    22.    
    23.   VScroll1.Move picContainer.Left + picContainer.Width, _
    24.      picContainer.Top, _
    25.      VScroll1.Width, _
    26.      picContainer.Height
    27.  
    28.   With Picture1
    29.     Set .Container = picContainer
    30.     .AutoSize = True
    31.     .Top = 0
    32.     .Left = 0
    33.   End With
    34.  
    35.   Command1.Caption = "Load Small Picture"
    36.   Command2.Caption = "Load Large Picture"
    37.  
    38.   With Command3
    39.     .Caption = ""
    40.     .Enabled = False
    41.     .Move VScroll1.Left, HScroll1.Top, VScroll1.Width, HScroll1.Height
    42.   End With
    43.  
    44. End Sub
    45. '-----------------------------------------------------------------
    46. Private Sub VScroll1_Change()
    47.   Picture1.Top = VScroll1.Value * -1
    48. End Sub
    49. '-----------------------------------------------------------------
    50. Private Sub VScroll1_Scroll()
    51.   Picture1.Top = VScroll1.Value * -1
    52. End Sub
    53. '-----------------------------------------------------------------
    54. Private Sub HScroll1_Change()
    55.   Picture1.Left = HScroll1.Value * -1
    56. End Sub
    57. '-----------------------------------------------------------------
    58. Private Sub HScroll1_Scroll()
    59.   Picture1.Left = HScroll1.Value * -1
    60. End Sub
    61. '-----------------------------------------------------------------
    62. Private Sub [b]SetScrollBars[/b]()
    63.   HScroll1.Value = 0
    64.   If Me.ScaleX(Picture1.Picture.Width, vbHimetric, vbPixels) > picContainer.ScaleWidth Then
    65.     HScroll1.Enabled = True
    66.     HScroll1.Max = Picture1.Width - picContainer.Width
    67.   Else
    68.     HScroll1.Enabled = False
    69.   End If
    70.   '
    71.   VScroll1.Value = 0
    72.   If Me.ScaleX(Picture1.Picture.Height, vbHimetric, vbPixels) > picContainer.ScaleHeight Then
    73.     VScroll1.Enabled = True
    74.     VScroll1.Max = Picture1.Height - picContainer.Height
    75.   Else
    76.     VScroll1.Enabled = False
    77.   End If
    78. End Sub
    Or if you are bored, try this.

    .
    this is simular to what im doing ,but i dont want no picture and to be honest there will be MANY command buttons, do i make a picture box and put the scroll bar on the side of it on the inside of it, or outside?

    And this is a stupid qurstion but who do i make it work? I never used a scroll bar before
    would be be something like this

    VB Code:
    1. Private Sub VScroll1_Change()
    2.   Picture1.Top = VScroll1.Value * -1
    3. End Sub
    4. '---------

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Is there a way to add a scroll bar to a list of command buttons?

    on a side note, is there a limit to the height of a picture box? because i have 1 inside another and everytime i set its height to 40000 i get an over flow error.

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Is there a way to add a scroll bar to a list of command buttons?

    Nevermind I got that fixed, but now i have a problem, when i scroll down, i cant see all of the buttons i put on there. Can this be adjusted? Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width