Results 1 to 7 of 7

Thread: Creating static buttons in a sidebar with scroll bar capabilities

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2024
    Posts
    14

    Lightbulb Creating static buttons in a sidebar with scroll bar capabilities

    I am wondering if you can create a sidebar with static buttons and able to have a scroll bar. I have a usercontrol as the sidebar with static buttons with the sidebar being 805 pixels in height, however the main form is only 407 pixels in height. When I add the scroll bar the bottom arrow is not showing on the main form, it must be at the bottom of the usercontrol, therefore being cut off. I am just wondering if it's better to add dynamically created buttons for this scenario? as I got it to show when I had dynamic buttons correctly.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: Creating static buttons in a sidebar with scroll bar capabilities

    Everything is possible, the question is how much work you want to put into it. Since your sidebar is much larger than your form, it seems pretty likely that you are right about the scroll bar arrow being off the bottom of the form.

    I'm not quite sure what you expect this to look like. Are there more buttons than there is room on the form, and you want to be able to scroll them? If so, you might consider a FlowLayoutPanel. Alternatively, you could roll your own. I won't go further with that, as I'm not sure whether I have your concept right.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2024
    Posts
    14

    Re: Creating static buttons in a sidebar with scroll bar capabilities

    The thing is that I am expecting the scrollbar to be 405px in height rather than 807 pixels in height. Is this possible?

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: Creating static buttons in a sidebar with scroll bar capabilities

    Well, yes. Why is it NOT that height? Either you set it to 807, or something else did. Presumably, you didn't do it, so what did? Some scrollbars are automatically added by forms and automatically set to the height of the visible form, but that doesn't seem to be the case here, either. So, I would assume that the scrollbar is being added by some process that you know about, and the height is what it is as a result of that process, whatever it is.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2024
    Posts
    14

    Re: Creating static buttons in a sidebar with scroll bar capabilities

    It's been added by the Main_loader

    Code:
       ' Declare VScrollBar1 with WithEvents
        Private WithEvents VScrollBar1 As New VScrollBar()
    
    
        Private Sub MainScreen_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ' Call a method to initialize dynamic controls
            Panel1.Visible = True
    
            ' Add the VScrollBar control to the form
            Controls.Add(VScrollBar1)
    
            ' Set the properties of the VScrollBar control
            VScrollBar1.Dock = DockStyle.Right
            VScrollBar1.Minimum = 0
    
            ' Set the small change value
            VScrollBar1.SmallChange = 20
    
            ' Set the value of the VScrollBar to 0 to ensure it starts at the top
            VScrollBar1.Value = 0
    
            ' Set the form's border style to FixedSingle to disallow resizing
            Me.FormBorderStyle = FormBorderStyle.FixedSingle
    
            ' Center the Label and PictureBox in Panel1
            Label1.Location = New Point((Panel1.Width - Label1.Width) \ 2, (Panel1.Height - Label1.Height - PictureBox1.Height - 10) \ 2)
            PictureBox1.Location = New Point((Panel1.Width - PictureBox1.Width) \ 2, Label1.Bottom + 10)
    
            ' Adjust the position and size of the scrollbar
            AdjustScrollBar()
            ' Handle the resize event to adjust the scrollbar size
            AddHandler Me.Resize, AddressOf AdjustScrollBar
        End Sub
    
        Private Sub AdjustScrollBar()
            ' Calculate the maximum value for the scroll bar based on the height of the user control and the height of the form
            Dim maxScrollValue As Integer = Math.Max(Panel1.Height - Me.ClientSize.Height, 0)
            VScrollBar1.Maximum = maxScrollValue
    
            ' Set the height of the scrollbar based on the available space
            Dim scrollBarHeight As Integer = Me.ClientSize.Height
            If maxScrollValue = 0 Then
                ' If there's no need for scrolling, set the scrollbar height to 0
                scrollBarHeight = 0
            Else
                ' Ensure that the scrollbar height is at least the size of the down arrow
                scrollBarHeight = Math.Max(scrollBarHeight, VScrollBar1.Width)
            End If
    
            VScrollBar1.Height = scrollBarHeight
        End Sub

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Creating static buttons in a sidebar with scroll bar capabilities

    You could use a Panel in your UserControl. The Panel would be tall enough to accommodate all of your Buttons. Your UserControl would be 407pixels height, and the ScrollBar would be used to scroll the Buttons into view. That’s the easiest way…

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Creating static buttons in a sidebar with scroll bar capabilities

    Just handle the VScrollBar _Scroll Event and set the Panel Top position

Tags for this Thread

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