Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7831701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:50:46+00:00 2026-06-02T11:50:46+00:00

I need simple TMemo that does NOT display scroll bars when they are not

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T11:50:51+00:00Added an answer on June 2, 2026 at 11:50 am

    If your memo is placed on the form, the form will be notifed with an EN_UPDATE when 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:

    type
      TForm1 = class(TForm)
        Memo1: TMemo;
        procedure FormCreate(Sender: TObject);
      protected
        procedure WMCommand(var Msg: TWMCommand); message WM_COMMAND;
      public
    
    ...
    
    procedure SetMargins(Memo: HWND);
    var
      Rect: TRect;
    begin
      SendMessage(Memo, EM_GETRECT, 0, Longint(@Rect));
      Rect.Right := Rect.Right - GetSystemMetrics(SM_CXHSCROLL);
      SendMessage(Memo, EM_SETRECT, 0, Longint(@Rect));
    end;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Memo1.ScrollBars := ssVertical;
      Memo1.Lines.Text := '';
      SetMargins(Memo1.Handle);
      Memo1.Lines.Text := 'The EM_GETRECT message retrieves the formatting ' +
      'rectangle of an edit control. The formatting rectangle is the limiting ' +
      'rectangle into which the control draws the text.';
    end;
    
    procedure TForm1.WMCommand(var Msg: TWMCommand);
    begin
      if (Msg.Ctl = Memo1.Handle) and (Msg.NotifyCode = EN_UPDATE) then begin
        if Memo1.Lines.Count > 6 then   // maximum 6 lines
          Memo1.ScrollBars := ssVertical
        else begin
          if Memo1.ScrollBars <> ssNone then begin
            Memo1.ScrollBars := ssNone;
            SetMargins(Memo1.Handle);
          end;
        end;
      end;
      inherited;
    end;
    

    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?.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need simple but reliable mechanism to ensure that table was not tampered with
I need something simple like date , but in seconds since 1970 instead of
I need simple program in C++ that will open text file and going line
I need a simple way to monitor multiple text log files distributed over a
I need a simple application, preferably a cross-platform one, that enables sending of files
I need simple hook for mercurial that checks commit comment using pattern. Here is
I need simple CMS to allow non-tech folks edit some static text in app
I need simple modbus Java library with source code. I found on google but
My requirement is that I need simple encryption/decryption methods in C# to encrypt and
I need simple code to do something like this. For example my old site

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.