开发者

Enable scroll bars in disabled TMemo control

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 kno开发者_开发百科w about the possible workaround with ReadOnly and color changes like in disabled state, but this would help me a lot.

Thanks in advance :)


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.


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


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;


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜