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
TRichEditand 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 aTToolButtonin aTToolbaras the 'bold' button. This will not make the editor lose its focus, because aTToolButtonis not a windowed control.If you do not wish to use a
TToolBar(or any equivalent control), simply use aTSpeedButtoninstead 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 itActnBoldor something. Set the caption to'Bold', the hint to'Make the selection bold.', add the shortcutCtrl+B, and writein its
OnExecuteevent. Then you can associate this action to any button, speed button, toolbar button, menu item, ..., simply by setting the control'sActionproperty toActnBold.If you really, really want to use a windowed control, such as a
TButton, then you can dobut it isn't beautiful (IMHO).