Enable scroll bars in disabled TMemo control

4.1k views Asked by At

Is there a way how to enable scroll bars in disabled TMemo component ? I want let the users scroll the content even if the control's Enabled property is set to False. I know about the possible workaround with ReadOnly and color changes like in disabled state, but this would help me a lot.

Thanks in advance :)

4

There are 4 answers

4
Marjan Venema On BEST ANSWER

A control can be disabled or enabled, but not half dis- and half enabled. (And, for the nit-pickers amongst us, I think no hack should make it so :-), for the reason given below).

Using ReadOnly is the easiest solution. Be mindful though with the color changes to not make the control look disabled. That would also be very confusing for the user with regard to recognizing enabled/disabled controls. It would be better to make it look like a scrollable multi-line label. That usually is done by setting the (background) color equal to the color of its parent.

Haven't used the solution suggested and linked by @HalloDu, but that looks like a good alternative.

1
HalloDu On

Well, it is not exactly, what you want, but the effect is the same. Look at this article where an ViewOnly Property for WinControls is implemented, which I found quite useful over the years. LINK

1
SimaWB On

That's not perfect way but it works : Use ScrollBar comp. adjacent to Memo.

procedure TForm9.FormCreate(Sender: TObject);
begin
  Memo1.ScrollBars := ssNone;
  ScrollBar1.Min := 0;
  ScrollBar1.Max := Memo1.Lines.Count div (Memo1.Height div 13);//13 is height of a line in memo
end;

procedure TForm9.ScrollBar1Scroll(Sender: TObject; ScrollCode: TScrollCode;
  var ScrollPos: Integer);
begin
  if ScrollCode in [scPageDown, scLineDown] then
    SendMessage(Memo1.Handle, WM_VSCROLL,  SB_PAGEDOWN,0)
  else if ScrollCode in [scPageUp, scLineUp] then
    SendMessage(Memo1.Handle, WM_VSCROLL,  SB_PAGEUP,0);
end;
2
Sam On

There is a way.

Place entire TMemo inside a TScrollBox.

When you fill the memo with text, adjust the height and width to accommodate the size of the text (that's another question but I'm sure it can be done)