tags:

views:

112

answers:

5

Hi!

How to make simpe Memo to be unfocusable, so if an user will click on it, focus will not be moved to it?

or

How to make a Label automaticly word wrap if it's text width > width of a label and make it height = height of text * 'visible' lines count?

Thanks!

+1  A: 
Memo1.Enabled := False;
TOndrej
And if the disabled look is undesirable put the (enabled) memo in a disabled panel.
Sertac Akyuz
No! it must looks lke enabled!
SomeOne
thats not enought it must be enabled to scroll through scrollbars
SomeOne
Not enabled = no active scrollbars. I also highly doubt you can scroll without giving focus to the component. Still giving focus, but you could also set the memo to read-only? `Memo1.ReadOnly := True`
Roald van Doorn
A: 

Here's a hack: Move the focus to some other control from TMemo.OnEnter:

procedure Form1.Memo1Enter(Sender: TObject);
begin
  Button1.SetFocus;
end;

I tried this on Delphi 2010 and Windows 7, it works just fine. The scrollbars are enabled, the memo looks enabled but you can't focus it and you can't select text from it (side effect of not being able to focus it).

Edit: You CAN actually copy text from it. Right click - select all, then right-click copy. It doesn't look like you selected something but it does work.

Cosmin Prund
+1  A: 

Do you want to make it so it can't be focused, or do you want to make it so it can't be typed into? Apparently you want it to still be scrollable and not have the "disabled look". Try setting the ReadOnly property to true. It will still be enabled, and the user can scroll through it and even select and copy text, but not edit the contents.

Mason Wheeler
+1  A: 

For how to make a Label automatically word wrap, use this option

Label1.WordWrap := True;

Edit 1: We must first set WordWrap property to false and later set that to True to automatically adjust the height.

Label1.WordWrap := False;
Label1.Caption := 'This has word wrap This has word wrap';
Label1.Width := 45;
Label1.WordWrap := true;
Bharat
This won't adjust its height to accommodate for the line count though..
Sertac Akyuz
@Sertac Akyuz: Thanks for the comment, above edit will automatically adjust the height.
Bharat
A: 

off the top of my head:

Make the memo tall enough to accommodate all the text at your selected width.

hide the memo's scrollbars. Set the memo to readonly

Place the memo on a TScrollbox with autoscroll set to true.

allow for the scrollbox vertical scrollbar in your width calculation.

Let the TScrollbox handle the scrolling.

Despatcher