|
-
February 7th, 2000, 10:26 PM
#1
horizontal scroll position in a richtextbox
i posted a similar question a few days ago about vertical scrolling...
i am creating a control that extends a richtextbox and autoformats all of its content. however, my formatting routine jumps the cursor back to the beginning. i now know how to store the currently scrolled vertical position, run my formatting routine, and jump back to its previously scrolled position - so that the user doesn't see any change - using the API.
(see http://codeguru.developer.com/bbs/wt...=threaded&sb=5)
is there a way to do this for the horizontal scroll position as well?
-
February 8th, 2000, 04:38 AM
#2
Re: horizontal scroll position in a richtextbox
You can get all kinds of information from a scroll bar using the GetScrollInfo API (that goes for TextBoxes and RichTextBoxes).
Here's some sample code (put into a form ) :
option Explicit
'
private Const SB_CTL = 2
private Const SB_HORZ = 0
private Const SB_VERT = 1
'
private Declare Function GetScrollInfo Lib "user32" (byval hWnd as Long, byval n as Long, lpScrollInfo as SCROLLINFO) as Long
'
private Type SCROLLINFO
cbSize as Long
fMask as Long
nMin as Long
nMax as Long
nPage as Long
nPos as Long
nTrackPos as Long
End Type
'
private Const SIF_RANGE as Long = &H1
private Const SIF_PAGE as Long = &H2
private Const SIF_POS as Long = &H4
private Const SIF_DISABLENOSCROLL as Long = &H8
private Const SIF_TRACKPOS as Long = &H10
private Const SIF_ALL as Long = (SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS)
'
public Enum eScrollBar
sbHorizontal = 0
sbVertical = 1
End Enum
'
public Function GetScrollBarPos(byval lHwnd as Long, byval ScrollBar as eScrollBar) as Long
'
Dim lFlag as Long
Dim sbInfo as SCROLLINFO
Dim lRet as Long
'
sbInfo.cbSize = len(sbInfo)
sbInfo.fMask = SIF_POS
lFlag = ScrollBar
'
lRet = GetScrollInfo(lHwnd, lFlag, sbInfo)
'
If lRet > 0 then ' ok
GetScrollBarPos = sbInfo.nPos
End If
'
End Function
You can now get the position of either the Vertical or Horizontal scrollbar by simply calling the GetScrollBarPos routine on the HWND of the control.
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|