Setting CustomColors in a ColorDialog

前端 未结 3 1283
花落未央
花落未央 2021-02-19 17:48

Custom color set in the color dialog are supposed to be set to {Blue, Blue} using the following code:

colorDialog1.CustomColors = new int[] { System.Drawing.Colo         


        
3条回答
  •  太阳男子
    2021-02-19 18:25

    You need to use OLE colors. The simplist way to achieve this is using the built in ColorTranslator object, e.g.

    colorDialog1.CustomColors = new int[] { 
                                            ColorTranslator.ToOle(Color.Blue), 
                                            ColorTranslator.ToOle(Color.Red)
                                          };
    colorDialog1.ShowDialog(); 
    

    If you need to convert from HTML colors, you can also use the ColorTranslator.FromHtml method, e.g.

    colorDialog1.CustomColors = new int[]
                                    {
                                        ColorTranslator.ToOle(Color.Blue), 
                                        ColorTranslator.ToOle(ColorTranslator.FromHtml("#FF0000"))
                                    };
    

提交回复
热议问题