0

「VisualStudioツールウィンドウ」を作成するためのVSpackage拡張機能を構築しています。ツールウィンドウ内に数字で構成されるグリッドがあります。ユーザーがグリッドの特定の行を選択した場合。その特定のコード行を強調表示する必要があります。

より明確にするために、私のグリッドに以下が含まれているとします。

行 1 ~ 10、行 2 ~ 15、行 3 ~ 14、

ユーザーが行 1 を選択すると、コード ウィンドウの 10 行目が強調表示されます。この機能は VisualStudio パッケージを使用して可能ですか? これは可能だと強く感じています。ほとんどの検索結果がそのように機能するからです。

同じことについての助けは大歓迎です!!

4

2 に答える 2

0

より単純なソリューションを使用することもできます。下記参照

  int lineNo = 3;
  if (!isProjectItemOpen)
  {
       Window win = projectItem.Open();
       win.Visible = true;
       Document doc = win.Document;
       doc.Activate();
       var ts = dte.ActiveDocument.Selection;
       ts.GotoLine(lineNo, true);
  }
于 2014-02-08T07:44:45.937 に答える
0

多くのグーグル検索に基づいて、最終的に私の投稿に対する答えを見つけました。これが他の人に役立つことを願っています。

上記のコード行を強調表示するには、「TextSelection」クラスを使用する必要があります。

        foreach (CodeElement codeElement in projectItem.FileCodeModel.CodeElements)// search for the function to be opened
        {
            // get the namespace elements
            if (codeElement.Kind == vsCMElement.vsCMElementNamespace)
            {
                foreach (CodeElement namespaceElement in codeElement.Children)
                {
                    // get the class elements
                    if (namespaceElement.Kind == vsCMElement.vsCMElementClass || namespaceElement.Kind == vsCMElement.vsCMElementInterface)
                    {
                        foreach (CodeElement classElement in namespaceElement.Children)
                        {
                            try
                            {
                                // get the function elements to highlight methods in code window
                                if (classElement.Kind == vsCMElement.vsCMElementFunction)
                                {
                                    if (!string.IsNullOrEmpty(highlightString))
                                    {
                                        if (classElement.Name.Equals(highlightString, StringComparison.Ordinal))
                                        {
                                            classElement.StartPoint.TryToShow(vsPaneShowHow.vsPaneShowTop, null);

                        classElement.StartPoint.TryToShow(vsPaneShowHow.vsPaneShowTop, null);

                            // get the text of the document
                         EnvDTE.TextSelection textSelection = window.Document.Selection as EnvDTE.TextSelection;

                            // now set the cursor to the beginning of the function
                            textSelection.MoveToPoint(classElement.StartPoint);
                            textSelection.SelectLine();

                                        }
                                    }
                                }
                            }
                            catch
                            {
                            }
                        }
                    }
                }
            }
        }
于 2013-04-16T13:08:10.093 に答える