Link to home
Start Free TrialLog in
Avatar of coondog091800
coondog091800

asked on

Prohibit scrolling in TMemo

I have several TMemos on a form and I need to be able to prohibit the user from scrolling in them except under certain conditions.  I must leave the Enabled property set to true because the TMemos have On-Click events associated with them.  ReadOnly is True and the Scrollbars is ssNone.  How can I prevent the user from scrolling?  Also, is there a way to prevent the user from selecting(highlighting) text?

Rich
Avatar of shaneholmes
shaneholmes

Use a TLabel (size to the size of memo)  &  A Memo

Both objects hold the same lines of strings

When you want to turn of the memo scrolling, set its visible property = False and the Labels = True.


The Label can hold a list of strings just like the memo
by setting its caption property =  MyStringList.Text;


sholmes
shaneholmes shares a nice idea,
may be in addition it should be:

Label.Color := clWindow;
Label.WordWrap := True;
Label.AutoSize := False;
Yeah, I figured all those cosmetics were pretty much a given - almost like adding any control - changing its properties to your liken....
<SMILE>

sholmes
Avatar of Eddie Shipman
Handle the arrow keys in the KeyDown, disables all caret movement, except by mouse:

procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key in [VK_DOWN, VK_UP, VK_RIGHT, VK_LEFT] then
    Key := 0;
end;


To prevent from selecting, set SelLength to 0 if it is > 0:

procedure TForm1.Memo1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if TMemo(Sender).SelLength > 0 then
    TMemo(Sender).SelLength := 0;
end;

Actuall, now thinking about it, you don't even have to check the SelLength, jusst set it
to 0 anytime the mouseup event is fired.

procedure TForm1.Memo1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  TMemo(Sender).SelLength := 0;
end;
ASKER CERTIFIED SOLUTION
Avatar of gandalf_the_white
gandalf_the_white
Flag of Austria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of coondog091800

ASKER

The main problem with the scrolling issue was that the application is using a touch screen monitor and for some reason if a person were to just keep rubbing their finger over the control it would scroll.  The setting focus to another control in the On Enter event turned out to be the most prudent solution and it fixed the problem.  Thanks to all of you for your input.

Rich