Domanda

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.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top