3

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 Answers4

7

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.

Marjan Venema
  • 19,136
  • 6
  • 65
  • 79
  • For more nit-picking - one can override some message handling to avoid the IBeam cursor and text selection etc.. – Sertac Akyuz Feb 23 '11 at 16:52
  • I don't think there's ever any need for color changes. When the user tries to enter text, and finds that it isn't going in they think, oh this is a read only box. – David Heffernan Feb 23 '11 at 21:04
  • 1
    @David: I happen to disagree. I hate it when I use a control thinking I can edit it and then find I can't. Usability seems to indicate this is not just a personal quirck. If the control were colored like a label I would immediately assume it is read only and not even try to change the contents, thereby avoiding the frustration of not being allowed to do what I want, possibily even without any clue as to why it isn't permitted. – Marjan Venema Feb 24 '11 at 07:35
  • 1
    I have the very special case, when all of the components on the form are disabled, so the users know, they can't change anything (it's also mentioned in the form's caption). They just want to read the whole text in the memos what is now impossible because of disabled scroll bars. I'll simply put them on the scroll boxes, what was the first idea, how to do it before I've asked here. Thanks for your time :) –  Feb 24 '11 at 11:12
1

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

HalloDu
  • 907
  • 1
  • 7
  • 16
  • Dead link, so sad... Wayback Machine: https://web.archive.org/web/20130329030656/http://delphi.about.com/od/vclusing/a/viewonly.htm – Dúthomhas Jul 15 '22 at 04:45
1

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;
SimaWB
  • 9,246
  • 2
  • 41
  • 46
0

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)

Sam
  • 2,663
  • 10
  • 41
  • 60
  • This answer is genius if I say so myself. :-) – Sam Feb 24 '11 at 00:32
  • Yes, you're right, it's the workaround I've had in my mind since I've got this request from a submitter. And because it's not possible to do it in the smooth way, I'll follow this up. +1 for you even if I wanted to know something else :) –  Feb 24 '11 at 11:04