Reputation: 349
I am currently trying to create an EDIT Control (http://msdn.microsoft.com/en-us/library/windows/desktop/bb775458(v=vs.85).aspx) in my Win32 Application but sadly, I cannot get the Vertical Scroll Bar to disappear when it's not in use.
I am using this style at the moment:
WS_CHILD | ES_MULTILINE | ES_WANTRETURN | WS_VISIBLE | WS_VSCROLL | ES_AUTOVSCROLL
This will show the Scroll Bar but it will be permanently visible even if not required. Ideally, I would like this bar to hide when not needed (i.e - When text fits onto control)
Is there a style I am missing or do I need to create a separate control with Scrolls and then embed the EDIT within it?
Thanks in Advance, Matt
Upvotes: 3
Views: 6000
Reputation: 596256
The standard EDIT
control does not support automatically showing/hiding the scrollbars. However, a standard RICHEDIT
control does, if you do not specify the ES_DISABLENOSCROLL
style.
Upvotes: 8
Reputation: 1232
The short answer in Win32 it's not possible with only style changes.
Even with MFC it's not integrated because scrollbars which show and hide change the client rect and you need to calculate the content size to detect when to show/hide the scrollbars. (Link to codeguru how to do that in MFC http://www.codeguru.com/cpp/controls/editctrl/article.php/c3917/Multiline-Edit-Box-with-Automatic-Scroll-Bar-Display.htm )
When you absolutely need show and hide of scrollbars your only option is to do that by code. You will need to overload the paint to calculate if the scrolls are needed or not and if you need to display them or not. Personally for those kind of work I usually hide scrollbars in the edit, and create two scrollbar control which I position, initialize and do everything myself. It's many lines of code, so be sure that you really need that before starting.
Upvotes: 2
Reputation: 89975
It's annoying, but there's no way to automatically make an Edit control show or hide its scroll bar as needed. You'll have to do it yourself. You could subclass the Edit control and call ShowScrollBar
as necessary in response to various window messages and notifications that affect the size or text (WM_SETTEXT
, WM_SETFONT
, WM_SIZE
, and EN_CHANGE
are the obvious ones that I can think of).
Upvotes: 10