如何从屏幕坐标获取行和列值 - VS2017 [英] How to get line and column values from screen coordinates - VS2017

查看:129
本文介绍了如何从屏幕坐标获取行和列值 - VS2017的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Visual Studio扩展,需要一种方法将屏幕坐标转换为VS编辑器中此时打开的文件的行和列值。是否有任何方法可以直接或已知的方法来获取此信息?
b


我发现一些较旧的论坛帖子提到这些信息的相关API未公开从VS2008开始暴露,并在VS2010中使用IWpfTextView中的方法解决方法。 从VS2017开始有没有改变?

解决方案

你好cabryant20,


>> ;我发现一些较旧的论坛帖子提到这些信息的相关API自VS2008以来未公开曝光,并且在VS2010中存在使用IWpfTextView中的方法的解决方法。 从VS2017开始有没有改变?


从以下文档中,我找不到相关属性或方法来从屏幕坐标获取行和列值。 / p>

https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.text.editor.iwpftextview?view=visualstudiosdk-2017


此外,你可以参考下面的代码,它编写一个自定义方法来通过YCoordinate获取ITextViewLine。

 private ITextViewLine GetTextViewLine(double y)
{
IWpfTextView textView = _textViewHost.TextView;
ITextViewLine textViewLineContainingYCoordinate = textView.TextViewLines.GetTextViewLineContainingYCoordinate(y);
if(textViewLineContainingYCoordinate == null)
textViewLineContainingYCoordinate =(y< = textView.TextViewLines [0] .Top)? textView.TextViewLines.FirstVisibleLine:textView.TextViewLines.LastVisibleLine;

返回textViewLineContainingYCoordinate;
}

https://github.com/tunnelvisionlabs/InheritanceMargin/blob/master/Tvl.​​VisualStudio.InheritanceMargin/InheritanceGlyphMouseHandler.cs


最佳问候,


张龙


I am working on a Visual Studio extension and need a way to convert screen coordinates to the line and column values for the file open in the VS editor at that point. Are there any methods to achieve this directly or known workarounds to get this information?

I have found some older forum posts that mention the relevant APIs for this information were not publicly exposed as of VS2008 and a workaround using methods in IWpfTextView existed in VS2010.  Has this changed as of VS2017?

解决方案

Hi cabryant20,

>>I have found some older forum posts that mention the relevant APIs for this information were not publicly exposed as of VS2008 and a workaround using methods in IWpfTextView existed in VS2010.  Has this changed as of VS2017?

From the following document, I could not find related properties or method to get line and column values from screen coordinates.

https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.text.editor.iwpftextview?view=visualstudiosdk-2017

In addition, you could refer the following code, which write a custom method to get ITextViewLine via YCoordinate.

private ITextViewLine GetTextViewLine(double y)
{
     IWpfTextView textView = _textViewHost.TextView;
     ITextViewLine textViewLineContainingYCoordinate = textView.TextViewLines.GetTextViewLineContainingYCoordinate(y);
     if (textViewLineContainingYCoordinate == null)
          textViewLineContainingYCoordinate = (y <= textView.TextViewLines[0].Top) ? textView.TextViewLines.FirstVisibleLine : textView.TextViewLines.LastVisibleLine;

     return textViewLineContainingYCoordinate;
}

https://github.com/tunnelvisionlabs/InheritanceMargin/blob/master/Tvl.VisualStudio.InheritanceMargin/InheritanceGlyphMouseHandler.cs

Best regards,

Zhanglong


这篇关于如何从屏幕坐标获取行和列值 - VS2017的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆