
Delphi™ Components:TBPRichEdit Added
TBPRichEdit has been added to the list
Delpi Components available for download. TBPRichEdit is a descendant of the native TRichEdit component. TBRichEdit has two additional scrolling events: OnVerticalScroll and OnHorizontalScroll. TBPRichEdit also adds properties (GutterSize, GutterColor, GutterTextColor) that display the TBPRichEditline numbers.
This component was developed due to a need to display line numbers (similar to TBPMemo) for a text listing. There was a slight twist; I wanted to
'colorize' certain text. Initially, my though was that it would only take a few moments to whip out this component, after all, the same code that adds the lines to the BPMemo could be used for a RichEdit.
WRONG!After creating the new component I realized that assigning the RichEdit as the parent of the PaintBox caused, well, issues. The text of the RichEdit was
'not being painted'. It was there. The text could be copied, pasted and cut, just not viewed within the RichEdit. After poking around a bit I did find one interesting tidbit that I had found in the
Delphi 2005 help file for the BringToFront Method of a control,
'Note that controls that wrap Windows screen objects (control classes descended from TWinControl) always "stack" above lightweight controls (control classes descended from TGraphicControl).'. This got me thinking (how relevant this is still remains to be seen) about a number of things regarding the way this whole thing was set up and how a RichEdit gets created and painted. After some thought, the easiest way around this was to actually create and TPanel to hold the TPaintBox and then draw the panel over the RichEdit (adjusting for the potential moving and sizing of the RichEdit). One important thing to note, when performing this technique the BorderStyle and HorizontalScrollBar height need to be considered when positioning the panel. Afterall, we want the panel to line up and appear as if it is
part of the RichEdit rather than something sitting on top of it. Covering the scroll bar is definitely quick way to screw that up.
At that point I only needed something to display the lines numbers for colored/highlighted text. I do at one point hope to adjust the line number positioning (centered) for the potential varying height of the lines of the TRichEdit. If there is anything else that you think should be added or see within the TBPRichEdit please let me know.
Labels: Code, Delphi, Information, Tech