Setting CustomColors in a ColorDialog

前端 未结 3 1284
花落未央
花落未央 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:22

    If you have an array of colors, you can translate them using Linq:

    colorDialog1.CustomColors = ThemeColors.Select(x => ColorTranslator.ToOle(x)).ToArray()
    

    The ThemeColors array would be something like this:

    public static Color[] ThemeColors
    {
       get => new[]
       {
          Color.FromArgb(255, 185, 0),
          Color.FromArgb(231, 72, 86),
          Color.FromArgb(0, 120, 215),
          Color.FromArgb(0, 153, 188),
          Color.DarkOrange
       }
    }
    

    Note: Don't forget to add:

    using System.Linq;
    

提交回复
热议问题