Forum > RichMemo
[SOLVED] Disallow selection TRichMemo
cpicanco:
Hi guys,
I was looking into https://github.com/skalogryz/richmemo TRichMemo (that inherits from StdCtrls.TCustomMemo) and would like to known if it is possible to disallow text selection and focus.
An alternative is simply doing RichMemo.Enabled := False (However the background of a disabled control changes and for my use case it must be unchanged).
Considering this first alternative, I would need to override the paint method to avoid background changes (However, I could not find a proper way of doing it and I just want to make sure it is really possible for this sort of control).
Can you shed some light on this issue, please!
Best,
R
cpicanco:
I just found an answer on StackOverflow that overrides a TMemo on Delphi.
https://stackoverflow.com/questions/55899526/how-to-draw-a-colored-line-to-the-left-of-a-tmemo-which-looks-like-a-gutter
I am considering to use the same technique in Lazarus. It should be possible, both have the WMPaint method.
cpicanco:
Well, I underestimate the complexity of this problem. :D
Would really appreciate any comments on how to disallow selection and focus and keep the background unchanged on a TCustomMemo descendant.
cpicanco:
Well, now I am considering hooking the colors using this approach:
https://theroadtodelphi.com/2012/02/06/changing-the-color-of-edit-controls-with-vcl-styles-enabled/
skalogryz:
--- Quote from: cpicanco on September 25, 2021, 03:29:46 pm ---An alternative is simply doing RichMemo.Enabled := False (However the background of a disabled control changes and for my use case it must be unchanged).
--- End quote ---
are you trying to use RichMemo as a rich-text Label?
setting "enabled" to false, might also prevent "scrolling" of the text. (not sure if it's critical for you or not).
Maybe you simply want to set to "ReadOnly := true". It doesn't prevent the selection... but maybe you don't want to prevent the selection after all? :)
The obvious benefit is that you don't have to mess with colors anymore.
And you can always set SetLength to zero, for OnSelhange event.
Navigation
[0] Message Index
[#] Next page