By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,510 Members | 1,451 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,510 IT Pros & Developers. It's quick & easy.

How to store/set the scrollbar's current position?

TheSmileyCoder
Expert Mod 100+
P: 2,321
I have a form, with a textbox "tb_RibbonXML". It contains alot of text, and as such has a scrollbar. Now when I am editing it, I will usually scrolldown, make a few edits, hit Ctrl-S to save and the record is saved, but the cursor position returns to the start of the textbox.

I have made code to store the cursors position within the textbox:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3. Private lngCursorPosition
  4. Private lngCursorSelectionLength
  5.  
  6. Private Sub tb_RibbonXml_BeforeUpdate(Cancel As Integer)
  7.       'Record cursor position
  8.       lngCursorPosition = Me.tb_RibbonXml.SelStart
  9.       lngCursorSelectionLength = Me.tb_RibbonXml.SelLength
  10. End Sub
  11.  
And code to reset it after an update:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_AfterUpdate()
  2.    On Error Resume Next
  3.       If Me.ID = lngRibbonID Then
  4.             If Screen.ActiveControl = Me.tb_RibbonXml Then
  5.                'Restore cursor position
  6.                Me.tb_RibbonXml.SelStart = lngCursorPosition
  7.                Me.tb_RibbonXml.SelLength = lngCursorSelectionLength
  8.             End If
  9.       End If
  10. End Sub
This works somewhat, but I would like to refine it more, by being able to store how far the textbox was scrolled down, and restore that information as well.

Anyone have some good suggestions?


This link could be usefull, but I am really not that good with using the declare function to get a function from an API.
Mar 30 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.