Question

I'm making an editor extension for VS2012, and I need to find the logical pixel width of any character in the editor.

I think that all characters share the same width, but the shared width changes as the zoom amount of the editor changes; when the zoom is at 100%, all characters are 7 logical pixels wide, otherwise they're all 7.33 logical pixels wide.

I can find the width of any character by writing:
// textview is an ITextView
textview.Caret.ContainingTextViewLine.TextWidth /
textview.Caret.ContainingTextViewLine.Length

However, the problem is when the line that the caret is on is empty, since that would be a division by zero.

Was it helpful?

Solution

I didn't find an answer to my question, but I found a solution to my problem:

VirtualSnapshotPoint Get_point(ITextCaret caret)
    {
    caret.ContainingTextViewLine.GetInsertionBufferPositionFromXCoordinate(...);
    }

That method made it unnecessary for me to work with the logical pixel width of any character.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top