Results 1 to 8 of 8

Thread: Implementing Scrolling in User Control..

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2001
    Location
    Buffalo, NY
    Posts
    297

    Implementing Scrolling in User Control..

    Hey All,

    I'm building my own User Control, and I was wondering if VB.NET offers some easy methods for scrolling in the control or will I jsut have to program the paint method to interpret the scroll bar locations and adjust accordingly?

    I'm drawing the entire control myself, if that makes a difference.

    Thanks,

    Ben

  2. #2
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Well, what you could do is put a panel on your usercontrol. Put everything else into that panel, resize the panel to fit the contents and set the usercontrol AutoScroll property to true.

    So if the panel is larger that the usercontrol scrollbars appear automatically.

    You mentioned that you paint everything yourself, so instead of the normal panel, you might wanna make your own panel that inherits from the regular panel. This way you can set doublebuffer and so on, to avoid flicker when painting.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2001
    Location
    Buffalo, NY
    Posts
    297
    Hey Pax,

    A lot of that went right over my head.

    I think I get the part about the panel and setting auto scroll, but unfortunatley I'm making a complicated control.

    It's a resource scheduler, so I need the list of resources on the left hand side to be stationary when you scroll the times horizontally. Almost like a ListView control in Detail mode, with the left-most column never being scrolled off.

    As far as the backbuffer, how would I implement something like that since I'm already running into flicker with my self-scrolling routines?

    Thanks!

    --Ben

  4. #4
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi Ben.

    Well it appears to be a bit more complicated than I first anticipated

    The flicker part can be avoided of you use doublebuffer.
    Example:
    If you paint you objects in a panel, than create a class that inherits a panel, and use that instead of the real panel.
    In the overridable sub OnCreateControl you can use the SetStyle method to active AllPaintingInWM, DoubleBuffer and UserPaint.
    This way, everything you paint in your derived panel, will actually be painted in a buffer first, and then painted to the panel when all painting has finished.

    For the scrolling part, I would use 3 panels. 2 panels on the control it self, one docked left and the other docked to fill.

    the third panel would be in the panels that's set to fill.
    Set the Autoscroll for the "fill"panel.

    Now draw everything in the third panel (this is the one that need to be derived to avoid flicker) and set the width of that panel to match the contents.
    This way, if the third panels is wider than the panel that contains it (the panel with dock=fill) a scrollbar will appear. This way you can scroll some of the contents, and have the left side of the control stationary.

    It's difficult to put in writing, but I hope it makes more sence now.

    On the attached picture I have tried to demonstrate what I mean.

    Green = UserControl
    Red = Stationary Panel, Docked left
    Yellow = Panel with autoscroll, Docked Fill
    Blue = Derived Panel , resized to fit contents.

    I hope this is of any help to you
    Attached Images Attached Images  
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2001
    Location
    Buffalo, NY
    Posts
    297
    Pax,

    That made a lot of sense. I think I've got a good understanding now of how to do it. The panels can be setup with Autoscroll themselves, so I can use them to create areas that scroll independantly.

    I'm sure I'll have many more questions, but for now, it's panel time! Thanks!

    --Ben

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2001
    Location
    Buffalo, NY
    Posts
    297
    Ho!

    First question!

    The way you showed me works great Pax, I'm glad you pointed out that the Panels could be used that way. Much appreciated.

    Here is the problem though....

    While the Horizontal Scrolling should only occur in the Right-side of the control, Vertical scrolling should be linked. Meaning I should only see one vertical scroll bar (preferably on the far right of the control) that scrolls both the right side of the control and the left.

    Any ideas?

    Thanks!

    --Ben

  7. #7
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi Ben.

    I'm glad it's working.

    But the bad news is, that the vertical scroll is pretty much screwing everything up for us here.

    I actually needed the excact same function while ago, and I ended up with not using autoscroll at all.

    I ended up with adding two regular scrollbars to my usercontrol.
    Whenever one of the panels were resized I would set the maximum of each scroll bar to the exceeding size, e.g. usercontrol.width-yellowpanel.width-yellowpanel.left and I would do the same for height. If the panels are smaller so the scrollbars aren't needed I would relocate the panels to their original place and disable the scrolbars.

    In the scrollevent I would relocate the panels to 0-scroll.value.
    This actually works fine, but everything we have done so far in the previous posts are useless

    Sorry about the bad news, but I hope this helps.
    Last edited by pax; Feb 12th, 2004 at 04:35 PM.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2001
    Location
    Buffalo, NY
    Posts
    297
    Pax,

    That's alright, I'm learning alot from doing this which is always valuable. And I only spent about an hour of my time working on that method.


    Moving the panels within their parent panel is a good idea too! That's much, MUCH easier than the way I was trying to implement it before.


    Again, thanks for your help!

    --Ben

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