VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Auto Show/Hide Vertical Scroll Bar in TextBox

by OzzyK (1 Submission)
Category: Miscellaneous
Compatability: Visual Basic 5.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (6 Votes)

Auto-show/hide vertical scroll bar in a multi-line TextBox control.
If you set the ScrollBars property of a multi-line TextBox control to 2-Vertical, the vertical scrollbar will be displayed whether or not there's any text in the TextBox, or the length of the text exceeds the visible area of the TextBox. So, if there's more text than the TextBox can display in its client area, then the vertical bar will be enabled, if not, it will still be displayed but disabled. This code subclasses a TextBox to intercept WM_KEYUP and WM_SIZE messages, and compares the height of the text to the height of the client area of the control. If the height of the text is greater than that of the client area, the vertical scroll bar will be displayed. Otherwise it will be hidden. So you don't have to see the disabled scroll bar when there's no need for it. I resorted to subclassing particularly to watch for the resizing of the TextBox. In this sample, the TextBox's size changes when the form is resized. Therefore subclassing may not be necessary as the Form_Resize event is perfectly suitable for doing whatever's needed. Yet the TextBox's size does not always change because of the form being resized. For example; there may be a splitter on the form, and the TextBox may be resized by that splitter. Or for some reason, the size of the TextBox may be programmatically changed. In such cases, I can't think of any way but subclassing to catch the TextBox's resizing.
The portions of the code pertaining to subclassing are, of course, nothing new as they are right out of Bruce McKinney's well-known "Hardcore Visual Basic", though a bit simplified. But for the rest of the code, I'd appreciate all feedback.

Assumes
Developed with MS Visual Basic 6 (SP5) on Windows XP

Rate Auto Show/Hide Vertical Scroll Bar in TextBox

Download Auto Show/Hide Vertical Scroll Bar in TextBox

Download Auto Show/Hide Vertical Scroll Bar in TextBox (5 KB)

Auto Show/Hide Vertical Scroll Bar in TextBox Comments

No comments have been posted about Auto Show/Hide Vertical Scroll Bar in TextBox. Why not be the first to post a comment about Auto Show/Hide Vertical Scroll Bar in TextBox.

Post your comment

Subject:
Message:
0/1000 characters