The CustomColors property claims to be a fixed array of 16 Colours, that you can preset in FormLoad, as defined here:
https://www.infragistics.com/help/winforms/infragistics.win.ultrawineditors~infragistics.win.ultrawineditors.ultracolorpicker~customcolors
private void Form1_Load(object sender, System.EventArgs e) { this.ultraColorPicker1.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid ; this.ultraColorPicker1.ButtonAppearance.BackColor = Color.Blue; // Display varying shades of yellow in custom area. for(int i = 0; i < 16; i++) this.ultraColorPicker1.CustomColors[i].Color = Color.FromArgb(255,255,15*i); }
This simply doesn't work, no custom colours are shown in the Palette dropdown when the form is displayed, all custom colours are empty.
How do I get them to display?
I'm using v17.2.20172.20139 of WinForms
Hi Robert,
The problem here is that you are using the wrong custom colors. It's a little confusing.
The UltraColorPicker used to only have one style - it used to be modelled after the Visual Studio color picker that you see in the property grid. That's great if you are a programmer, but that style includes system colors and other features which aren't very useful for the average user who isn't a software developer.
If you switch back to the old (VisualStudio) style, you will see the custom colors you are setting here on the Custom tab. So here's your code with the addition of setting the Style first:
this.ultraColorPicker1.Style = Infragistics.Win.UltraColorPalette.ColorPickerEditorStyle.VisualStudio; this.ultraColorPicker1.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid; this.ultraColorPicker1.ButtonAppearance.BackColor = Color.Blue; // Display varying shades of yellow in custom area. for (int i = 0; i < 16; i++) { this.ultraColorPicker1.CustomColors[i].Color = Color.FromArgb(255, 255, 15 * i); }
If you do this and run your applicaiton, then drop down the color picker and switch to the Custom tab, you will see the custom colors (various shades of yellow) on the bottom.
A little while ago, we added the new ColorPalette style to the UltraColorPicker. This style looks better, doesn't have confusing system colors, and is much nicer and easier to use for graphic designers and users who are not programmers. This new style makes use of the ColorPalette object, which can be shared amongst many UltraColorPicker controls so you can apply the same settings and customization to multiple controls. The custom colors for this new style on the on PaletteInfo.
So, here's your code again, except this time I left it using the new style, but I change where the colors are added. Instead of adding them to CustomColors on the UltraColorPiciker control itself, I add them to the PaletteInfo. This is, I think, what you probably want for your application.
this.ultraColorPicker1.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid; this.ultraColorPicker1.ButtonAppearance.BackColor = Color.Blue; // Display varying shades of yellow in custom area. for (int i = 0; i < 16; i++) { //this.ultraColorPicker1.CustomColors[i].Color = Color.FromArgb(255, 255, 15 * i); this.ultraColorPicker1.PaletteInfo.CustomColors.Add(Color.FromArgb(255, 255, 15 * i)); }
It may also be worth noting that the custom colors aren't really intended to be set by you, the developer. They are really intended for the user to set and modify so that they can have a place to store commonly-used colors.
If you have a set of colors you want to add to the ColorPicker as part of the built-in colors for your application and you don't want the user to change them, you would be better off adding them to the ColorPalette rather than the custom colors.How you do that depends on what you want - you could add new rows or new columns to the palette, or replace rows/columns of existing colors. But a simple way to add 2 new rows would be something like this:
var ultraColorPalette = this.ultraColorPicker1.PaletteInfo; var row = ultraColorPalette.Rows.Add(); row.SpacingBefore = 2; for (int x = 0; x < ultraColorPalette.Columns.Count; x++) { row[x] = Color.FromArgb(255, 255, 15 * x); } row = ultraColorPalette.Rows.Add(); row.SpacingBefore = 2; for (int x = 0; x < ultraColorPalette.Columns.Count; x++) { row[x] = Color.FromArgb(255, 255, 15 * (x+8)); }
Adding extra rows to the palette works perfectly, and is exactly what I wanted thank you.
Regarding user Custom Colours, as soon as the colour picker is closed, it does indeed save those colours, and displays them the next time that picker is opened, but only for the life of the form that hosts the picker. As soon as that form is closed and reopened, the custom colours are cleared, so it seems to me I would have to store them elsewhere and add them to the pickers customcolours each time, if I want them to be stored between form instances. Am I missing something?
Secondly, is there a way for the user to delete a custom colour once they have added them? It seems like the list just gets bigger and bigger, with no way to delete one in the UI.
The custom colors are stored on the UltraPaletteInfo, and this object has save and load method so you can save the custom colors or any other customization to a file or a stream.
Save:
var ultraColorPalette = this.ultraColorPicker1.PaletteInfo; ultraColorPalette.SaveAsXml("filename.xml", Infragistics.Win.UltraColorPalette.PaletteInfoCategories.All);
Load:
var ultraColorPalette = this.ultraColorPicker1.PaletteInfo; ultraColorPalette.LoadFromXml("filename.xml", Infragistics.Win.UltraColorPalette.PaletteInfoCategories.All);
In the code I have here, I am passing in "All" for the categories to save. This means it's going to save everything, including the palette itself, and the other properties and setting like the Style. But if you want, you could narrow it to just the "CustomColors" option.
To remove a custom color, the user can simply click and drag and then drop it somewhere outside the custom colors box. Users can also drag a color from the grid palette and drop it into the Custom Colors box.
Awesome, thank you.
This works perfectly, just what I wanted, thanks again.
Final question in this area, is there a way to get the Ribbon or Toolbars Popup colour picker to use this Palette approach? At the moment it seems to be a cut down version, then links to the standard Windows Color dialog.
The UltraToolbarsManager color picker is based on MS Office - so there's no built-in color tool that matches the UltraColorPicker.
If you want a color picker on a toolbar or ribbon and you don't need the tool to show up in more than one place (i.e. on a menu AND a ribbon) then you could use a ControlContainerTool and place an UltraColorPicker on the ribbon or toolbar directly.