Reputation: 3028
Greetings collective wonderfolk of the internet.
I'm trying to underline specific words in a TEdit (actually a TNxEdit from Berg NextSuite - but it's a derivative of TEdit). However in order to do this I need to know the pixel coordinates of said word.
This is fairly easy to do if the start of the text is visible, however I can't work out how to do it if the start of the text has been scrolled off the end.
Is there some way of determining the exact coordinates of a given word directly? Failing that, determining which text is visible in the edit and which isn't? Or some other ingenious method.
Edit1: To cover some of the current answers:
The requirements are to implement a spell checker on a column of a TNxGrid component, which limits me to TNxEdit. If I could choose which component I used I would have switched by now :(
I can do the drawing the line. TNxEdit has a canvas that allows me to draw the underline quite happily providing I can work out the correct coordinates.
If the start of the edit text is visible, i.e. there's no scrolling off the front, then I can determine the correct start position and the length of the line using TextExtent.
The issue comes in the scenario where the start of the text has scrolled off the front. Not being able to determine how much is scrolled off the front means I can't work out the starting position for the line. The length of the line becomes a problem if the word I want to highlight is also partially scrolled.
Upvotes: 3
Views: 890
Reputation: 8768
Try using (sending the message) EM_POSFROMCHAR for getting coordinates of specific part of the text. For example:
pPoint: TPoint;
SendMessage(Wnd, EM_POSFROMCHAR, WPARAM(@pPoint), charIndex);
But bear in mind, that underlining will most likely require you to subclass the control and implement custom painting. So the suggestion that @GolesTrol made can be worthwhile, that is try to choose from existing controls, which already supports required functionality.
Upvotes: 8
Reputation: 6484
TEdit is a Delphi wrapper for system Win32 Edit class and it doesn't provide any functions to set underline attribute on a specific word , neither TEdit add such a feature . i suggest you consider using a more powerful class, component in delphi , as TRichEdit Said that , if you like to face complex task , try calculating string extent given a font (see GetTextExtentExPoint and similar) to get the x start/end position of the line, (also consider the border of Edit to add some x offset) and draw a line on the HDC (TCanvas)
Upvotes: -1