Reputation: 1
In Visual C#.NET:
I want to be able to make a color dialog, and have it so that the user can only select a few colors (specifically the ones available for command prompt/batch files). How is this done? How can I restrict what colors the user can choose?
Also, is there a way to "dock" the color dialog so that it doesn't open up in a new form, but stays in my main form?
Upvotes: 2
Views: 4089
Reputation: 47490
The following are some of the useful properties of the ColorDialog control in your case. But none of them satisfy your constrant. I think in your case you have to create your own dialog box with your custom colors list.
AllowFullOpen - Specifies whether the user can choose custom colors.
CustomColors - A collection of custom colors picked by the user.
FullOpen - Specifies whether the part used to pick custom colors are automatically open.
Users can create their own set of custom colors. These colors are contained in an Int32 composed of the ARGB component (alpha, red, green, and blue) values necessary to create the color. Custom colors can only be defined if AllowFullOpen is set to true. So, it's not possible to set CustomColors and restrict others.
Upvotes: 0
Reputation: 24182
Could this be what you want?
private void ShowColorDialog()
{
ColorDialog cd = new ColorDialog();
cd.CustomColors = new int[] { ToInt(Color.Red), ToInt(Color.Blue), ToInt(Color.YellowGreen) };
cd.SolidColorOnly = true;
cd.ShowDialog();
}
static int ToInt(Color c)
{
return c.R + c.G * 0x100 + c.B * 0x10000;
}
I think you cannot dock the color dialog.
Upvotes: 5