Results 1 to 15 of 15

Thread: [RESOLVED] Panel Scrollbar does not work (TableLayoutPanel with Picture Boxes inside)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2010
    Location
    Glogow, Poland
    Posts
    104

    Resolved [RESOLVED] Panel Scrollbar does not work (TableLayoutPanel with Picture Boxes inside)

    Hi All,

    I wonder if anybody could help me figure out how to add working scrollbar to a Panel in VB.Net (Visual Studio 2010).

    Here is what I do.

    I have a Panel which resizes with the form (anchored to Left, Right, Top, Bottom). Inside the Panel I have a TableLayoutPanel. There are only 5 cells, each containing a PictureBox.

    Most of the time the TableLayoutPanel is larger then the Panel, so I would like to add a vertical scrollbar to the Panel, so I could scroll up and down to see all the pictures. Sadly this does not work at all. Even if I add a scrollbar to the Panel using code it does not actually scroll.

    Is there an easy way of doing this?

    Attached is an example of what I'm trying to do.
    Name:  Scrollbar_needed.PNG
Views: 9145
Size:  47.5 KB

  2. #2
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Panel Scrollbar does not work (TableLayoutPanel with Picture Boxes inside)

    Have you tried setting the Panel's AutoScroll property to True instead of adding a separate slider?

    BB

  3. #3
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Panel Scrollbar does not work (TableLayoutPanel with Picture Boxes inside)

    Did you set the AutoScroll property on the Panel?
    It should automatically add a vertical scrollbar if the child controls exceed the height of the panel.
    I had no issue with it. (p.s. shouldn't have taken time to verify it worked, could have beat bb. Interesting the timing...no response for 2 1/2 hours, then two at approximately the same time)
    Last edited by passel; Oct 26th, 2014 at 08:59 AM.

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

    Re: Panel Scrollbar does not work (TableLayoutPanel with Picture Boxes inside)

    While those two answers are likely the best, I'm curious what you were doing in the scrollbar events when the value changed?
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2010
    Location
    Glogow, Poland
    Posts
    104

    Re: Panel Scrollbar does not work (TableLayoutPanel with Picture Boxes inside)

    Thanks a lot for the replies.

    @boops boops and passel - changing Autoscroll to True does nothing. The scrollbar does not appear.

    @Shaggy Hiker - are you suggesting adding a separate VScrollBar and making it respond to things happening wihthing the Panel?

  6. #6
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Panel Scrollbar does not work (TableLayoutPanel with Picture Boxes inside)

    Are you sure you are setting AutoScroll property of the Panel, as both I and Passel said, and not the TableLayoutPanel? And are you sure that the TableLayoutPanel is inside the Panel, not just on top of it. You can check that in the DocumentOutline window (View/Other Windows/Document Outline).

    BB

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Sep 2010
    Location
    Glogow, Poland
    Posts
    104

    Re: Panel Scrollbar does not work (TableLayoutPanel with Picture Boxes inside)

    Hi boops boops

    Yes I'm sure I'm setting Autoscroll property of the Panel and nothing else.

    I managed to bring up the scrollbar by puting the TableLayoutPanel into another Panel (Panel2) and then inserting the Panel2 into Panel1. Unfortunatelly in this scenario I cannot resize my TableLayoutPanel with the form and/or the Panel1. Whenever I dock the Panel2 inside Panel1 or anchor it to Left Right Top Bottom it matches the size of the Panel1 and we are back to square one.

    The TableLayoutPanel supposed to be bigger than the Panel (Panel1) holding it most of the time, so I wouldn't mind to have a scrollbar all the time.

    Any other ideas? Please

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Panel Scrollbar does not work (TableLayoutPanel with Picture Boxes inside)

    This is confusing me a bit. The reason I asked what I did was that it sounded like you had already manually added a scrollbar to the panel, and I was asking what you had done in response to the events of that scrollbar. Now, you talk about putting a TableLayoutPanel (TLP) in a Panel (P2), which you are then putting in another Panel (P1). That would result in TLP in P2 in P1. What's the point of that second panel?
    My usual boring signature: Nothing

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Sep 2010
    Location
    Glogow, Poland
    Posts
    104

    Re: Panel Scrollbar does not work (TableLayoutPanel with Picture Boxes inside)

    Hi Shaggy Hiker. The point of the P2 is to bring up the vertical scrollbar in the P1. If there is only the TLP in the P1 that scrollbar does not show up.

    I'm a bit lost now. This was supposed to be very simple thing to setup, but proves to be problematic.

    Maybe I'll explain what is my goal. I need to display 5 pictures/photos. At any given time about 1,5 of picture should be in view, so you would scroll to see the other pictures. The form (window) will change size and the panel holding the photos and the photos themselves should grow and shrink proportionally with the form, but we should always have about 1,5 of a photo in view.

    I know how to adjust the size of graphic to match the changing size of picturebox.

    What I do not know is how to make it possible to scroll the TLP. I put it into a Panel hoping the scrollbar will come up automatically, but it doesn't.

    I started by putting 5 photos directly into the Panel, but when the Panel size changes and the size of photos changes with it, the photos are either overlapping or gaps between them get too big. This is why I decided to use the TLP, which distributes the photos evenly when their sizes are changing, but then you cannot scroll the Panel (my original question).

    I would appriciate any other ideas you may have.

    BTW - FlowLayoutPanel won't work for me.

  10. #10
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Panel Scrollbar does not work (TableLayoutPanel with Picture Boxes inside)

    Since you haven't attached an example project so we can see the hierarchy of how your anchoring and docking the various components it is hard to make a suggestion.
    Attached is my simple test case, and you will see it adds the scrollbar.
    Attached Files Attached Files

  11. #11
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Panel Scrollbar does not work (TableLayoutPanel with Picture Boxes inside)

    I'll bet it's something quite simple. Just send us the Designer code of the form (insert it between[code] ... [/code] tags) and we will probably be able to try it out or spot it straight away. In case you don't know, to get the designer code you click the second icon (Show All Files) at the top of the Solution Explorer window, expand the Form item, and send the contents of the formname.Designer.vb file.

    BB

    edit: this time Passel beat me to it! It's all those tags that did it.

  12. #12
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Panel Scrollbar does not work (TableLayoutPanel with Picture Boxes inside)

    Also, just for kicks, I don't know how you're changing the size of the TableLayoutPanel to choose how much scrolling you have to do, so I added a little code to increase the height proportionately so that you essentially keep the same scrolling distance and the picture will expand both vertically and horizontally. The example as posted in post #10, only shrunk the image if you made the form too skinny, but didn't increase the image above the original size, as the vertical size of the TableLayoutPanel was never modified.
    This code modifies the vertical size of TableLayoutPanel in proportion to the panel vertical size. Just replace the code in the post #10 example.
    Code:
    Public Class Form1
      Dim RefBaseHeight As Single
      Dim Baseheight As Single
    
      Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        PictureBox1.BackgroundImage = Image.FromFile("C:\Users\Public\Pictures\Sample Pictures\Blue hills.jpg")
        PictureBox2.BackgroundImage = Image.FromFile("C:\Users\Public\Pictures\Sample Pictures\Sunset.jpg")
        PictureBox3.BackgroundImage = PictureBox1.BackgroundImage
        PictureBox4.BackgroundImage = PictureBox2.BackgroundImage
        PictureBox5.BackgroundImage = PictureBox1.BackgroundImage
      End Sub
    
      Private Sub Form1_Activated(sender As Object, e As System.EventArgs) Handles Me.Activated
        If RefBaseHeight = 0 Then
          RefBaseHeight = Panel1.Height
          Baseheight = TableLayoutPanel1.Height
        End If
      End Sub
    
      Private Sub Panel1_Resize(sender As System.Object, e As System.EventArgs) Handles Panel1.Resize
        If BaseHeight > 0 Then
          TableLayoutPanel1.Height = CInt(Baseheight * (Panel1.Height / RefBaseHeight))
        End If
      End Sub
    End Class
    Last edited by passel; Oct 26th, 2014 at 03:28 PM.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Sep 2010
    Location
    Glogow, Poland
    Posts
    104

    Re: Panel Scrollbar does not work (TableLayoutPanel with Picture Boxes inside)

    Thanks a lot for the replies.

    ok... let's use the sample project prepared by passel. This is pretty much the same thing I did initially.

    I see that pictureboxes' widths are resizing when you make the form wider. Cool - this is the stuff I need to happen.

    Now... how to make the pictureboxes' height to rise when you expand the form vertically? At this point I got lost and tried pretty much everything. I tring anchoring the TLP to the Panel and making the TLP taller then the Panel, which does the trick with resizing in width and height, but then the scrollbar dissapears.

    So how to make the pictureboxes resizable in widht and height with the scrollbar in the Panel? Is this at all possible?

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Sep 2010
    Location
    Glogow, Poland
    Posts
    104

    Re: Panel Scrollbar does not work (TableLayoutPanel with Picture Boxes inside)

    Thanks a lot passel for your latest reply.

    This should do the trick.

    I'll try to adjust your solution slightly to my needs and if it will work fine I'll mark the thread 'resolved'. I guess I will be able to confirm if it fully works in about 2 days (it is getting late here in Europe and I'll be busy tomorrow).

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Sep 2010
    Location
    Glogow, Poland
    Posts
    104

    Re: Panel Scrollbar does not work (TableLayoutPanel with Picture Boxes inside)

    Hi All,

    I managed to adjust the code examples provided by passel to my needs, so I'm marking this thread resolved. Thank you passel.

    @everybody who participated - thanks a lot for replies!

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