473,382 Members | 1,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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.SelectedIndex = 1) When they double-click on
the content in tab2, they are taken back to tab1.
(tabImageTabs.SelectedIndex = 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:
ScrollBarLocation = tabThumbNails.VerticalScroll.Value
tabImageTabs.SelectedIndex = 1

Here's the code I am using to move back to the tab1 with the verticle scroll
value set:
tabImageTabs.SelectedIndex = 0
tabThumbNails.VerticalScroll.Value = ScrollBarLocation

(At this point, I get my tab1 back in front, but the scroll bar is back at
the top.)
Oct 18 '08 #1
4 3363
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.VerticalScroll.Value.

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 ScrollBarLocation As Integer

Private Sub tabThumbNails_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tabThumbNails.DoubleClick
ScrollBarLocation = tabThumbNails.VerticalScroll.Value
tabImageTabs.SelectedIndex = 1
End Sub

Private Sub TabPage2_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tabPage2.DoubleClick
tabImageTabs.SelectedIndex = 0
Timer1.Start()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
tabThumbNails.VerticalScroll.Value = ScrollBarLocation
If (tabThumbNails.VerticalScroll.Value = ScrollBarLocation) Then
Timer1.Stop()
End If
End Sub
End Class

Cheers,
Randy

Oct 18 '08 #2
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

"OmegaSquared" <Om**********@discussions.microsoft.comwrote in message
news:CD**********************************@microsof t.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.VerticalScroll.Value.

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 ScrollBarLocation As Integer

Private Sub tabThumbNails_DoubleClick(ByVal sender As Object, ByVal e
As
System.EventArgs) Handles tabThumbNails.DoubleClick
ScrollBarLocation = tabThumbNails.VerticalScroll.Value
tabImageTabs.SelectedIndex = 1
End Sub

Private Sub TabPage2_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tabPage2.DoubleClick
tabImageTabs.SelectedIndex = 0
Timer1.Start()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
tabThumbNails.VerticalScroll.Value = ScrollBarLocation
If (tabThumbNails.VerticalScroll.Value = ScrollBarLocation) Then
Timer1.Stop()
End If
End Sub
End Class

Cheers,
Randy

Oct 19 '08 #3
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
"OmegaSquared" <Om**********@discussions.microsoft.comwrote in message
news:CD**********************************@microsof t.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.VerticalScroll.Value.

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 ScrollBarLocation As Integer

Private Sub tabThumbNails_DoubleClick(ByVal sender As Object, ByVal e
As
System.EventArgs) Handles tabThumbNails.DoubleClick
ScrollBarLocation = tabThumbNails.VerticalScroll.Value
tabImageTabs.SelectedIndex = 1
End Sub

Private Sub TabPage2_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tabPage2.DoubleClick
tabImageTabs.SelectedIndex = 0
Timer1.Start()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
tabThumbNails.VerticalScroll.Value = ScrollBarLocation
If (tabThumbNails.VerticalScroll.Value = ScrollBarLocation) Then
Timer1.Stop()
End If
End Sub
End Class

Cheers,
Randy

Oct 21 '08 #4
I've solved this problem. Instead of setting the value of the scroll bar,
which does not reposition it, I have used the ScrollControlIntoView method
of the container object. I run through my collection of thumbnails and grab
their Y coordiante. Since the ScrollControlIntoView 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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim ICPosition As Point

Dim ICY As Integer

For Each ImageControl As Windows.Forms.Control In tabThumbNails.Controls

ICPosition = ImageControl.Location

ICY = ICPosition.Y

If ImageControl.Height - tabThumbNails.Height + ICY 0 Then

tabThumbNails.ScrollControlIntoView(ImageViewers.I tem(CInt(ImageControl.Name)))

End If

Next

End Sub
Oct 21 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: ojorus | last post by:
Hi! I just wonder how I can save a page's scroll position with javascript. (i'm not a javascript developer) I have a PHP-page with two columns; the left contains a lot of thumbnails, and the right...
1
by: JezB | last post by:
There are a few references on the net about how to restore a page's scroll position over a postback. eg. http://www.devhood.com/messages/message_view-2.aspx?thread_id=104625 My question is : can...
5
by: JezB | last post by:
There are a few references on the net about how to restore a page's scroll position over a postback. This is a simple one which works for me: eg....
1
by: JC | last post by:
I'm sure you've all seen the save scroll position from 4 guys from rolla which can be found here > http://aspnet.4guysfromrolla.com/articles/111704-1.aspx BUT try to get that to work AND still be...
0
by: Mirover | last post by:
how can I use the "result set " (fill a temp table) with the returned result set of querys like this : restore filelistonly,restore headeronly...
7
by: Lit | last post by:
Hi, How can I capture the vertical scroll bar position for a Listbox. I have a Listbox of 100 items + when I click on it I post back remove the item selected. After returning to the client...
1
by: limonn | last post by:
Hi guys i m trying to find a way to restore the scroll position in an applet. I was trying : (document.all)?document.applets.scrollTop:window.pageYOffset); ...
12
Frinavale
by: Frinavale | last post by:
I think I'm trying to do something impossible. I have a <div> element with a overflow style set to "scroll". In other words my <div> element allows the user to scroll the content within it. ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.