Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations danielledunham on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To Know When The Bottom Of A Rich Text Box Is Reached 1

Status
Not open for further replies.

TripleJHJO

Programmer
Jan 10, 2003
76
US
I have a form with a richtextbox that I am using as a basic word editor. How can I programatically tell when the text is scrolling beyond the bottom of the box.
I don't think that I can count lines, due to the fact that different fonts can produce the ability for variable lines.

Thanks,
J.Jensen
 
It will scroll automatically. What are you trying to do?

-David
2006 & 2007 Microsoft Most Valuable Professional (MVP)
2006 Dell Certified System Professional (CSP)
 
I want to restrict the user to the text box without letting them go beyond the visual border.
The text box is the size of the label they are printing on. I do not want them to type beyond the size of text box, because it will not be printable on the label.
 
You might consider testing for the presence of scroll bars in the RichText change event.

for example:

Code:
'add a richtextbox and set its scrollbars property to 3-rtfBoth and paste code to test

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const WS_HSCROLL = &H100000
Private Const WS_VSCROLL = &H200000

Public Function ScrollBarCheck() As Boolean
    Dim RTBScrollBars As Long
    'check for presence of scroll bars
    RTBScrollBars = GetWindowLong(RichTextBox1.hwnd, GWL_STYLE)
    If (RTBScrollBars And WS_VSCROLL) <> 0 Or (RTBScrollBars And WS_HSCROLL) <> 0 Then
        'VScroll Bar IS Present
        ScrollBarCheck = True
    Else
        'VScroll Bar IS Not Present
        ScrollBarCheck = False
    End If
End Function

Private Sub RichTextBox1_Change()
    If ScrollBarCheck = True Then
        'warn user that data will not fit
        MsgBox "Exceeds Printable Area"
    Else
    End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top