So I looked through other user's question but couldn't find on specifically upon what I am looking for. What I am trying to do is very simple. I am writing a Visual Studio Macro and am trying to obtain the number of the current line that the TextSelection
is on. So that's it really, my question is quite simple. How do you get the number of the line that the selection is currently at? Any help is greatly appreciated!
Just so it's clear to anybody reading this, I am using VB and am writing Visual Studio Macro.
Keep in mind that a TextSelection can span multiple lines, so there's potentially a range of lines.
Looking at the docs for TextSelection (i.e. I haven't tested this), you should be able to do something like this:
Dim mySelection As EnvDTE.TextSelection = ' however you get the active selection
mySelection.TopPoint.Line ' gets the line of the top of the selection
If you want to get it based on where the cursor is (top or bottom of the selection) you can try this:
mySelection.ActivePoint.Line
It looks like the TextRanges might also be useful, but it sounds like it's for box selection only, so it might not apply.
mySelection.TextRanges.Item(0).Line