Locked Vertical Scroll Bar

  • Tuesday, July 31, 2012 8:10 PM
     
     

    Visual Basic 2010 has a control called "VScrollBar" I added it to a form which requires vertical scrolling.

    Unfortunately I can't find any instructions for using the control, simply adding it to the form doesn't do anything.

    Any Suggestions?

    Milt


    sirmilt

All Replies

  • Tuesday, July 31, 2012 8:29 PM
     
     

    The control selected, you can press F1 and read the documentation how to use it.

    Here's an overview of all controls: Controls to Use on Windows Forms

    inlcuding HScrollBar and VScrollBar Controls

    EDIT: Note that several controls also have an AutoScroll property, so maybe you do not have to implement scrolling on your own.


    Armin


  • Tuesday, July 31, 2012 9:23 PM
     
     

    Armin, thanks for the super quick response.

    I had reviewed the documentation previously and it left a lot of unanswered question, or items that I just don't comprehend.

    In view of the fact that there is a control called "VScrollBar" in the Visual Basic 2010 Tool Box, the  code to initialize a control seems superfluous. But, I had tried it anyway to no avail.

    I tried the control from the Tool Box but couldn't get it to work because I just did not know what properties had to be set.

    As of now after reading and trying all the documented items that I could find, I still haven't the vaguest idea how to add a vertical scroll bar to a windows form in Visual Basic 2010.

    Milt


    sirmilt

  • Tuesday, July 31, 2012 10:13 PM
     
     Answered Has Code

    Create a new Winforms application and a Form like this: (the left window is the document outline window to show you the relation of the controls).

    A Picturebox inside a Panel, and a VScrollbar. All default properties (all but the backcolor of the panel).

    Use this code:

    Public Class Form1
    
       Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
          MyBase.OnLoad(e)
    
          PictureBox1.Location = Point.Empty
          PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
    
          Dim bmp As New Bitmap(Panel1.Width, Panel1.Height * 3)
    
          Using g = Graphics.FromImage(bmp)
             g.Clear(Color.Black)
             g.DrawLine(Pens.Red, 0, 0, bmp.Width, bmp.Height)
             g.DrawLine(Pens.Red, 0, bmp.Height, bmp.Width, 0)
             g.DrawRectangle(Pens.Red, 0, 0, bmp.Width - 1, bmp.Height - 1)
          End Using
    
          PictureBox1.Image = bmp
    
          VScrollBar1.Minimum = 0
          VScrollBar1.LargeChange = Panel1.ClientSize.Height
          VScrollBar1.Maximum = PictureBox1.Image.Height - 1
    
       End Sub
       Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll
    
          PictureBox1.Top = -VScrollBar1.Value
    
       End Sub
    
    End Class
    

    Then just try it and let me know if it's clear now.


    Armin