Restore Scroll Bar Position on Tab

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Engel

    Restore Scroll Bar Position on Tab

    I have an application on which I have a tab control with two tabs. When a
    user double-clicks on an item in tab1 of my tabs collection, tab2 becomes
    the visible tab. (tabImageTabs.S electedIndex = 1) When they double-click on
    the content in tab2, they are taken back to tab1.
    (tabImageTabs.S electedIndex = 0)

    When tab1 is restored, I have lost the position of the scrollbar and the
    user must re-scroll to get back to where they were. I've tried setting the
    scroll value (grab the verticlescroll value when leaving tab1 and assigning
    it that value when I go back, but it doesn't seem to work.

    Any ideas?
    Here's the code I use to capture the position of the scrollbar when changing
    to tab2:
    ScrollBarLocati on = tabThumbNails.V erticalScroll.V alue
    tabImageTabs.Se lectedIndex = 1

    Here's the code I am using to move back to the tab1 with the verticle scroll
    value set:
    tabImageTabs.Se lectedIndex = 0
    tabThumbNails.V erticalScroll.V alue = ScrollBarLocati on

    (At this point, I get my tab1 back in front, but the scroll bar is back at
    the top.)


  • =?Utf-8?B?T21lZ2FTcXVhcmVk?=

    #2
    RE: Restore Scroll Bar Position on Tab

    Hello, Paul,
    I tried a few experiments with this and it does indeed seem flaky. I
    wasn't able to find any "nice" solution. But I guess that there is some
    timing problem involved where the TabPage is trying to scroll the
    top-leftmost control into view and so it only partly pays attention to the
    value that you are setting into tabThumbNails.V erticalScroll.V alue.

    The only thing I could do to get it to perform reasonably was to add a timer
    and use it to set the scroll position. Even then, the value I tried to set
    wouldn't "take" on the first attempt. Hence I kept the timer going until the
    TabPage was finally persuaded to take the scroll value.

    This is definitely not a pretty solution, but here it is anyway:

    Public Class Form1
    Private ScrollBarLocati on As Integer

    Private Sub tabThumbNails_D oubleClick(ByVa l sender As Object, ByVal e As
    System.EventArg s) Handles tabThumbNails.D oubleClick
    ScrollBarLocati on = tabThumbNails.V erticalScroll.V alue
    tabImageTabs.Se lectedIndex = 1
    End Sub

    Private Sub TabPage2_Double Click(ByVal sender As Object, ByVal e As
    System.EventArg s) Handles tabPage2.Double Click
    tabImageTabs.Se lectedIndex = 0
    Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As
    System.EventArg s) Handles Timer1.Tick
    tabThumbNails.V erticalScroll.V alue = ScrollBarLocati on
    If (tabThumbNails. VerticalScroll. Value = ScrollBarLocati on) Then
    Timer1.Stop()
    End If
    End Sub
    End Class

    Cheers,
    Randy

    Comment

    • Paul Engel

      #3
      Re: Restore Scroll Bar Position on Tab

      Thanks, Randy. Yup, it's a bit messy, but it solves the problem. I really
      appreciate your taking the time to play w/ it. I'll implement your solution
      ASAP!!!

      Paul

      "OmegaSquar ed" <OmegaSquared@d iscussions.micr osoft.comwrote in message
      news:CD275837-5150-4E78-963F-E94BC87B1553@mi crosoft.com...
      Hello, Paul,
      I tried a few experiments with this and it does indeed seem flaky. I
      wasn't able to find any "nice" solution. But I guess that there is some
      timing problem involved where the TabPage is trying to scroll the
      top-leftmost control into view and so it only partly pays attention to the
      value that you are setting into tabThumbNails.V erticalScroll.V alue.
      >
      The only thing I could do to get it to perform reasonably was to add a
      timer
      and use it to set the scroll position. Even then, the value I tried to
      set
      wouldn't "take" on the first attempt. Hence I kept the timer going until
      the
      TabPage was finally persuaded to take the scroll value.
      >
      This is definitely not a pretty solution, but here it is anyway:
      >
      Public Class Form1
      Private ScrollBarLocati on As Integer
      >
      Private Sub tabThumbNails_D oubleClick(ByVa l sender As Object, ByVal e
      As
      System.EventArg s) Handles tabThumbNails.D oubleClick
      ScrollBarLocati on = tabThumbNails.V erticalScroll.V alue
      tabImageTabs.Se lectedIndex = 1
      End Sub
      >
      Private Sub TabPage2_Double Click(ByVal sender As Object, ByVal e As
      System.EventArg s) Handles tabPage2.Double Click
      tabImageTabs.Se lectedIndex = 0
      Timer1.Start()
      End Sub
      >
      Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As
      System.EventArg s) Handles Timer1.Tick
      tabThumbNails.V erticalScroll.V alue = ScrollBarLocati on
      If (tabThumbNails. VerticalScroll. Value = ScrollBarLocati on) Then
      Timer1.Stop()
      End If
      End Sub
      End Class
      >
      Cheers,
      Randy
      >

      Comment

      • Paul Engel

        #4
        Re: Restore Scroll Bar Position on Tab

        Randy,

        I have tried this and what I find is that the scroll bar verticle value
        changes immediately, but when the tab is returned to the focus, the scroll
        bar does not move. It stays at the 0 position. Any ideas?

        Paul
        "OmegaSquar ed" <OmegaSquared@d iscussions.micr osoft.comwrote in message
        news:CD275837-5150-4E78-963F-E94BC87B1553@mi crosoft.com...
        Hello, Paul,
        I tried a few experiments with this and it does indeed seem flaky. I
        wasn't able to find any "nice" solution. But I guess that there is some
        timing problem involved where the TabPage is trying to scroll the
        top-leftmost control into view and so it only partly pays attention to the
        value that you are setting into tabThumbNails.V erticalScroll.V alue.
        >
        The only thing I could do to get it to perform reasonably was to add a
        timer
        and use it to set the scroll position. Even then, the value I tried to
        set
        wouldn't "take" on the first attempt. Hence I kept the timer going until
        the
        TabPage was finally persuaded to take the scroll value.
        >
        This is definitely not a pretty solution, but here it is anyway:
        >
        Public Class Form1
        Private ScrollBarLocati on As Integer
        >
        Private Sub tabThumbNails_D oubleClick(ByVa l sender As Object, ByVal e
        As
        System.EventArg s) Handles tabThumbNails.D oubleClick
        ScrollBarLocati on = tabThumbNails.V erticalScroll.V alue
        tabImageTabs.Se lectedIndex = 1
        End Sub
        >
        Private Sub TabPage2_Double Click(ByVal sender As Object, ByVal e As
        System.EventArg s) Handles tabPage2.Double Click
        tabImageTabs.Se lectedIndex = 0
        Timer1.Start()
        End Sub
        >
        Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As
        System.EventArg s) Handles Timer1.Tick
        tabThumbNails.V erticalScroll.V alue = ScrollBarLocati on
        If (tabThumbNails. VerticalScroll. Value = ScrollBarLocati on) Then
        Timer1.Stop()
        End If
        End Sub
        End Class
        >
        Cheers,
        Randy
        >

        Comment

        • Paul Engel

          #5
          Re: Restore Scroll Bar Position on Tab

          I've solved this problem. Instead of setting the value of the scroll bar,
          which does not reposition it, I have used the ScrollControlIn toView method
          of the container object. I run through my collection of thumbnails and grab
          their Y coordiante. Since the ScrollControlIn toView method simply makes sure
          the control is showing at the bottom of the viewable container, I have to
          subtract the height of the container from my calculation to position the
          control at 0,0. Here's the button I wrote to test this:

          Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
          System.EventArg s) Handles Button1.Click

          Dim ICPosition As Point

          Dim ICY As Integer

          For Each ImageControl As Windows.Forms.C ontrol In tabThumbNails.C ontrols

          ICPosition = ImageControl.Lo cation

          ICY = ICPosition.Y

          If ImageControl.He ight - tabThumbNails.H eight + ICY 0 Then

          tabThumbNails.S crollControlInt oView(ImageView ers.Item(CInt(I mageControl.Nam e)))

          End If

          Next



          End Sub


          Comment

          Working...