【问题标题】:highlighting selected line in active window with some colour c#(notepad++ plugin)用一些颜色突出显示活动窗口中的选定行 c#(notepad++ 插件)
【发布时间】:2017-01-05 03:15:52
【问题描述】:

您好,我正在使用 c# 做一个 notepad++ 插件

我需要的是,以某种颜色显示给定行号之间的活动窗口。假设我有第 2 行和第 8 行,那么它必须以绿色突出显示第 2 行和第 8 行之间的记事本++ 屏幕。

从活动窗口读取

        int length = (int)Win32.SendMessage(GetCurrentScintilla(), SciMsg.SCI_GETLENGTH, 0, 0);
        IntPtr ptrToText = Marshal.AllocHGlobal(length + 10);
        Win32.SendMessage(GetCurrentScintilla(), SciMsg.SCI_GETTEXT, length+10, ptrToText);
        String InputFromActiveWindow = Marshal.PtrToStringAnsi(ptrToText);

聚焦选定行的代码

       Win32.SendMessage(curScintilla, SciMsg.SCI_ENSUREVISIBLE, lineNumber, 0);
        Win32.SendMessage(curScintilla, SciMsg.SCI_GOTOLINE, lineNumber, 0);
        Win32.SendMessage(curScintilla, SciMsg.SCI_GRABFOCUS, 0, 0);
        Win32.SendMessage(curScintilla, SciMsg.SCI_GRABFOCUS, 0, 0);

//答案是

win32.SendMessage(PluginBase.nppData._scintillaMainHandle, SciMsg.SCI_MARKERDEFINE, 1, (int)SciMsg.SC_MARK_BACKGROUND);
            Win32.SendMessage(PluginBase.nppData._scintillaMainHandle, SciMsg.SCI_MARKERSETBACK, 1, 0x99FF00);
            for (int linetobeHighlighted = StartLine; linetobeHighlighted <= EndLine; linetobeHighlighted++)
            {
                Win32.SendMessage(PluginBase.nppData._scintillaMainHandle, SciMsg.SCI_MARKERADD, linetobeHighlighted, 1);
            }

【问题讨论】:

  • 请分享您的尝试?
  • 我实际上不知道该尝试什么。到目前为止我尝试的是从活动窗口读取。并在给出行号时转到特定行。用于从活动窗口读取的代码
  • @Richa Garg 我已将代码附加到问题中
  • 参考stackoverflow.com/questions/21478948/… 突出显示文本

标签: c# notepad++ programmers-notepad


【解决方案1】:

要突出显示选定的文本,请使用

Win32.SendMessage(PluginBase.GetCurrentScintilla(),
              SciMsg.SCI_SETSELBACK, 1, 0xFFFF00);

更多详情请参考Notepad++ plugin - find and highlight text

【讨论】:

  • 这里我手动选择了 text.instaed 我应该传递行号并突出显示应该发生
  • win32.SendMessage(PluginBase.nppData._scintillaMainHandle, SciMsg.SCI_MARKERDEFINE, 1, (int)SciMsg.SC_MARK_BACKGROUND); Win32.SendMessage(PluginBase.nppData._scintillaMainHandle, SciMsg.SCI_MARKERSETBACK, 1, 0x99FF00); for (int linetobeHighlighted = StartLine; linetobeHighlighted
猜你喜欢
  • 2012-05-12
  • 1970-01-01
  • 2012-04-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-24
  • 2020-11-04
  • 2015-06-10
相关资源
最近更新 更多