Using delphi and rich edit, I need to replicate something along the lines of this very editor I'm writing in, when you select a text and press on the Bold button, the text remains selected instead of unselecting and losing focus.
How can I achieve this?
Thank you.
OK, now I think I see the issue. You have a
TRichEdit
and aTButton
. Then you do something likeand you are annoyed by the fact that the Rich Edit control loses its focus when you click
Button1
. Normally you use aTToolButton
in aTToolbar
as the 'bold' button. This will not make the editor lose its focus, because aTToolButton
is not a windowed control.If you do not wish to use a
TToolBar
(or any equivalent control), simply use aTSpeedButton
instead of aTButton
.The normal way of doing this, however, is to use a
TActionList
. Drop such a control on your form, and then add a new action, call itActnBold
or something. Set the caption to'Bold'
, the hint to'Make the selection bold.'
, add the shortcutCtrl+B
, and writein its
OnExecute
event. Then you can associate this action to any button, speed button, toolbar button, menu item, ..., simply by setting the control'sAction
property toActnBold
.If you really, really want to use a windowed control, such as a
TButton
, then you can dobut it isn't beautiful (IMHO).