I need simple TMemo that does NOT display scroll bars when they are not needed (ie insufficient text), but does when they are. something like ScrollBars = ssAuto or like the TRichEdit HideScrollBars.
I have tried to subclass a TMemo and use the ES_DISABLENOSCROLL in the CreateParams like in the TRichEdit but it does not work.
Edit: This should work with or without WordWrap enabled.
If your memo is placed on the form, the form will be notifed with an
EN_UPDATEwhen the text has been changed and the contents will be redrawn. You can decide here if there will be any scroll bars. I’m assuming we’re playing with the vertical scroll bar and there’s no horizontal scrollbar:The thing with setting the right margin is that, removing/putting vertical scroll bar looks utter ugly if the text has to be restructured to fit in.
Note that the above example assumes a maximum of 6 lines. To know how many lines could fit in your memo see this question:
How do I determine the height of a line of text in a TMemo programmatically?.