0

我正在尝试为我正在编写的记事本 ++ 插件设置 Markerbackgrounds,以便可以突出显示某些行。颜色存储为从 Color.ToArgb() 转换的整数:

int colour = Convert.ToInt32(Color.LightSkyBlue.ToArgb())

根据我对 Scintillia 文档的了解,它只接受 RGB 颜色,因此我使用以下函数去除颜色的 Alpha 部分。这确实设置了一种颜色,但不是蓝色,而是橙色而不是蓝色。这是设置标记背景颜色的正确方法吗?

       private static void DefineColor(int type, int colour)
    {
        string hexValue = colour.ToString("X");
        hexValue = hexValue.Remove(0, 2);

        //hexValue = "0x" + hexValue

        int decValue = Convert.ToInt32(ColorTranslator.FromHtml(hexValue));
        //int decValue = int.Parse("FF", System.Globalization.NumberStyles.AllowHexSpecifier);

        Win32.SendMessage(PluginBase.nppData._scintillaMainHandle, SciMsg.SCI_MARKERDEFINE, type, (int)SciMsg.SC_MARK_BACKGROUND);
        Win32.SendMessage(PluginBase.nppData._scintillaMainHandle, SciMsg.SCI_MARKERSETBACK, type, decValue);
        Win32.SendMessage(PluginBase.nppData._scintillaMainHandle, SciMsg.SCI_MARKERSETFORE, type, 0);
    }
4

1 回答 1

0

这会去除任何 alpha 值:

var colorOnly = Color.FromArgb(c.R, c.G, c.B);

这会将颜色转换为整数值:

int i = c.ToArgb();

两者一起:

int i = Color.FromArgb(c.R, c.G, c.B).ToArgb();

但我不知道,Scintillia 是否使用相同的颜色表示。可以将值存储为 BGR 而不是 RGB 格式。

int bgr = (c.B * 256 + c.G) * 256 + c.R;
于 2011-12-15T17:47:33.897 回答