Question

I'm building a custom edit control which consists of adding both an icon at the left and an icon button at the right, both inside the edit control. This requires shifting the starting point of the text (and cursor) to the right by X amount of pixels. This also means I need to 'Limit' how wide the text can be drawn too, to make room for the button on the right. The intention is to provide both a custom icon on the left, such as in a browser, as well as an 'X' button on the right to clear the contents of the edit control.

How to offset the Rect of where to draw the text and cursor in a TCustomEdit descendant?

Was it helpful?

Solution

If you are using more recent version of Delphi, there should already be a TButtonedEdit Control and can do your work.

If not, I think you can send a EM_SETMARGINS message to your TCustomEdit to set the left and right margin.

SendMessage(CustomEdit.Handle, EM_SETMARGINS, EC_LEFTMARGIN or EC_RIGHTMARGIN, MakeLong(LeftMargin, RightMargin));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top