• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 392
  • Last Modified:

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
0
coondog091800
Asked:
coondog091800
  • 3
  • 2
  • 2
  • +2
1 Solution
 
shaneholmesCommented:
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
0
 
esoftbgCommented:
shaneholmes shares a nice idea,
may be in addition it should be:

Label.Color := clWindow;
Label.WordWrap := True;
0
 
esoftbgCommented:
Label.AutoSize := False;
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
shaneholmesCommented:
Yeah, I figured all those cosmetics were pretty much a given - almost like adding any control - changing its properties to your liken....
<SMILE>

sholmes
0
 
Eddie ShipmanAll-around developerCommented:
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;


0
 
Eddie ShipmanAll-around developerCommented:
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;

0
 
Eddie ShipmanAll-around developerCommented:
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;
0
 
gandalf_the_whiteCommented:
in our programs we just move the focus away from the memo- or rtf-field
whenever the user clicks into it.
that means the OnEnter event does a setfocus to another control.

if there is no reason the caret should visible in the field then this is
quite a nice and easy solution
0
 
coondog091800Author Commented:
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
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now