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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RichTextBox Visible ScrollBars check 1

Status
Not open for further replies.

robdon

Programmer
May 21, 2001
252
ES
Hi,

Does anyone know how to detect if a RichTextBox has the Vertical Scroll Bar visible.

Not the RichTextBox.ScrollBars property.

But if RichTextBox.ScrollBars = rtfBoth, I need to actually know if the scroll bar is visible at a certain time.

Because if the RichTextBox does not have many lines in it, then the scrollbar is not visible, and I need to know if the scroll bar is there or not.

Thanks,

Rob D
 
This should work:
Code:
Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const EM_GETLINECOUNT = &HBA

Private Sub RichTextBox1_Change()
Dim LineCt As Long
LineCt = SendMessage(RichTextBox1.hwnd, EM_GETLINECOUNT, 0&, 0&)
End Sub
Once you have the line count, it's just a matter of knowing how many lines before you have a scroll bar. How to do this depends on things like whether you dynamically resize the control and so on.

HTH

Bob
 
This won't be entirely reliable if you have multiple font sizes supported, though. Maybe someone else can improve this.
 
Hi,

My rich text box is dynamically sized, so it can change.

Any other ideas, anyone?

Thanks,

Rob D.
 
You can check the presence of a scroll bar by checking the corresponding bit in window style. A window contains WS_VSCROLL and WS_HSCROLL style bits to indicate the presence of vertical and horizontal scroll bar respectively.
___
[tt]
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
...
Dim dwStyle As Long
dwStyle = GetWindowLong(RichTextBox1.hwnd, GWL_STYLE)
If (dwStyle And WS_VSCROLL) Then Debug.Print "Has Vertical SB"
If (dwStyle And WS_HSCROLL) Then Debug.Print "Has Horizontal SB"[/tt]
 
Hi Hypetia,

That was just what I was looking for.

Thanks for the help,

Rob D.
 
There you go! I felt pretty sure there was something like that somewhere.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top