How to get caret's x,y or rectangle

hi, i’m trying to find how to get the caret’s position in x,y coordinates because i have to show a window exactly in this place, something similar to code completion but totally custom.
i’m pretty sure exists, but i’m not able to find it. any help?
thanks
David

Hi David,

Please use the Position property of SyntaxEdit control (or TextEditor in case of WPF):

https://docs.alternetsoft.com/api/Alternet.Editor.SyntaxEdit.Position.html

Kind regards,
Dmitry

hi Dmitry,
thanks for the answer, i noticed i forgot to write “pixel” in my question.
Position give x,y in characters, there is a way for get the rectangle-in-pixels of the x,y-character?
i’m using the winform version.
thanks,
David

Hi David,

You should use TextToScreen\PointToScreen methods to get caret position in screen coordinates like this:

        var pos = syntaxEdit1.Position;
        pos = syntaxEdit1.TextToScreen(pos);
        pos = syntaxEdit1.PointToScreen(pos);
        int width = syntaxEdit1.SyntaxPaint.MeasureLine(pos.Y, pos.X, 1);
        int height = syntaxEdit1.Painter.LineHeight;           
        // get rectangle around current char
        var rectangle = new Rectangle(pos.X, pos.Y, width, height);

Kind regards,
Andrew