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

How do you determine if vertical scroll bar is visible in RichTextBox 1

Status
Not open for further replies.

SBendBuckeye

Programmer
May 22, 2002
2,166
US
Hello All,

How do you determine whether or not Vertical ScrollBars are visible in a RichTextBox (even if they are disabled). I am using MeasureString with the rich text box CreateGraphics and font. I think I need to use SystemInformation but I am not sure of that. Thanks in advance for any ideas and/or suggestions!
 
Not a great deal of help, but the VScroll event is fired as soon as the Vertical ScrollBar appears (but not when it disappears).

I think you may have to delve into this at a lower level.

[vampire][bat]
 
A solution, I think.

[tt]Private MyRTBInnerSize As Integer[/tt]

Before the RTB contains any text:

[tt]MyRTBInnerSize = MyRTB.Width - MyRTB.ClientSize.Width[/tt]

This gives the width of RTB less the borders

When you need to check for a Vertical ScrollBar

[tt]If (MyRTB.Width - MyRTB.ClientSize.Width) > MyRTBInnerSize Then MessageBox.Show("Vertical ScrollBar is visible") [/tt]


Hope this helps.




[vampire][bat]
 
Right solution, wrong explanation:

MyRTBInnerSize is the total actual "border width", therefore if the new "border width" is bigger, then the Vertical ScrollBar is present.

Sorry for any confusion, but I initially tested the code the other way round and didn't change the variable name after I changed the code.



[vampire][bat]
 
SBendBuckeye, did you find a better solution?

I need to determine whether or not the scrollbar is visible for a project that I've just started on and was planning to use my method unless you have a more precise one.

[vampire][bat]
 
SBendBuckeye thanks for that link. It is reassuring to know that (apart from using API calls) my solution was correct - even if I don't like it much, but I think I'll stick with it.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top