Is there any way to disable selecting of text in a memo control because it's very anoying.
The memo is Read Only.
- 2Are you sure that your users will never need to copy a part of the text in the memo?Andreas Rejbrand– Andreas Rejbrand2011-10-26 18:43:07 +00:00Commented Oct 26, 2011 at 18:43
- @Andreas Rejbrand No because it is ReadOnlyLittle Helper– Little Helper2011-10-26 18:43:53 +00:00Commented Oct 26, 2011 at 18:43
- 1Setting enable to false will prevent selection, but also stop scrollbars from working.LU RD– LU RD2011-10-26 18:52:24 +00:00Commented Oct 26, 2011 at 18:52
- 1But if I disable the memo, font color changes.Little Helper– Little Helper2011-10-26 18:57:30 +00:00Commented Oct 26, 2011 at 18:57
- 2TLabel may be suitable if you change its font and background color.Roman Yankovsky– Roman Yankovsky2011-10-26 19:15:45 +00:00Commented Oct 26, 2011 at 19:15
4 Answers
I think you should rethink. I realise that your control is used in read-only mode, but still, what if the end user wishes to copy a part of the text? Then he needs to be able to select the part in question.
Still, if you are certain that you need to disable every kind of selection, the easiest approach is to use a TRichEdit instead of the TMemo, and do simply
procedure TForm1.RichEdit1SelectionChange(Sender: TObject); begin RichEdit1.SelLength := 0; end; 2 Comments
You could also use the onMouseUp event
procedure TForm1.Memo1MouseUp(Sender: TObject: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if Memo1.SelLength > 0 then Memo1.SelLength := 0; end; But, that doesn't stop selecting with the keyboard..
or you could also use the onEnter, and just change the focus to another control on your form.
procedure TForm1.Memo1Enter(Sender: TObject); begin Edit1.SetFocus; end; 1 Comment
OnEnter).I played around with TRichEdit and TMemo until I was bored to tears. Yes, you can do a few tricks with event handling on the object, but it still is not the desired effect - and the cursor winds up blinking somewhere. So the best thing I could find was to use TLabel. I'm using Borland C++ Builder 6, and the \n is translated correctly with inline text strings for TLabel. So,
Label1->Caption = "this is a test of the emergency\n" "broadcast station, this is only\n" "a test. If this had been an\n" "actual emergency, blah blah blah...\n"; Works just fine. I haven't tried to read in from a file, but I'm certain that if the stream were exactly as seen it would also work. Since you are going to have to enter or read in the text you want displayed anyway - this should work well instead of using a bunch of TLabels for each line. If you have a concern for word wrapping, you will have to process that portion separately. If it static, then just do it by hand like I did in the example. I sure hope this helps or at least gives an idea...
- atomkey -
Comments
As i understand you would like to use memo as label actually (and sometimes it really have sense). When i need to use TcxMemo (memo component from DeveloperExpress) as label i use such simple procedure:
procedure ShowMemoAsLabel(m: TcxMemo); begin m.Enabled := False; m.Properties.ReadOnly := True; // AH: Unfortunately it doesn't copy some important properties, maybe it will // be fixed in future versions of DEX, but at moment we do some job ourselves. m.StyleDisabled := m.Style; m.StyleDisabled.BorderColor := m.Style.BorderColor; m.StyleDisabled.BorderStyle := m.Style.BorderStyle; m.StyleDisabled.Color := m.Style.Color; m.StyleDisabled.Edges := m.Style.Edges; m.StyleDisabled.Shadow := m.Style.Shadow; m.StyleDisabled.TextColor := m.Style.TextColor; m.StyleDisabled.TextStyle := m.Style.TextStyle; m.StyleDisabled.TransparentBorder := m.Style.TransparentBorder; end;