Change the TextBox highlight color when a user selects text?

前端 未结 2 1415
你的背包
你的背包 2020-12-15 22:43

I\'ve been looking for the way to change the textbox highlight color when a user select text. Windows uses blue as default color. For example, on Microsoft Outlook, when you

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-15 23:05

    Hi here is the code to change the selection colour just keep in mind that you will have to store the current colour and then once you've changed the colour and your application closes you would need to restore it because this changes the colour of the whole computer not just for the current process.

        [DllImport("user32.dll")]
        static extern bool SetSysColors(int cElements, int[] lpaElements, uint[] lpaRgbValues);
    
    
        void ChangeSelectColour(Color color)
        {
            const int COLOR_HIGHLIGHT = 13;
            const int COLOR_HIGHLIGHTTEXT = 14;
            // You will have to set the HighlightText colour if you want to change that as well.
    
    
            //array of elements to change
            int[] elements = { COLOR_HIGHLIGHT };
    
    
            List colours = new List();
            colours.Add((uint)ColorTranslator.ToWin32(color));
    
            //set the desktop color using p/invoke
            SetSysColors(elements.Length, elements, colours.ToArray());
        }
    

提交回复
热议问题