I am having trouble using the CustomColors property in the ColorDialog control.
I have created an int array from ARGB values and assigned it to the CustomColors property of my ColorDialog control. AllowFullOpen has been set to true.
Yet when I execute ShowDialog, the boxes specified for custom colors display only black.
Here's my code:
int[] customColors = new int[4];
customColors[0] = Color.Beige.ToArgb();
customColors[1] = Color.CadetBlue.ToArgb();
customColors[2] = Color.Chocolate.ToArgb();
customColors[3] = Color.DeepPink.ToArgb();
this.colorDialog.AllowFullOpen = true;
this.colorDialog.AnyColor = true;
this.colorDialog.CustomColors = customColors;
DialogResult dr = this.colorDialog.ShowDialog();
The ColorDialog displays 4 black squares and 12 white squares in the Custom Colors section.
What am I doing wrong here?
Tony Lin
Fremont, CA
You may work around this by using the following static method
public static int ColorToColorref(Color clr)
{
return (clr.R + (clr.G << 8) + (clr.B << 16));
}
e.g.
customColors[0] = ColorToColorref(Color.Biege);
Be free to let me know if you have any questions on this issue, Thanks!
Kind regards,
Ying-Shen Yu [MSFT]
Microsoft Support Engineer
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2001 Microsoft Corporation. All rights
reserved.
Thanks for your excellent tip.
Now that I can select from my list of custom colors, I have another
question.
The ColorDialog's "Add to Custom Colors" doesn't seem to work.
First, I can only change the first custom color in the array. The other
custom color in the array can't be changed.
Second, "Add to Custom Colors" doesn't do any good since no changes are
saved.
When I rerun this, my custom colors int array is unchanged.
Am I missing something, or is this a defect in the ColorDialog control?
Tony Lin
"Ying-Shen Yu" <v-...@online.microsoft.com> wrote in message
news:J#DgVXYXD...@cpmsftngxa06.phx.gbl...
int[] customColors = new int[]{....};
dlg.CustomColors = customColors;
DialogResult dr = dlg.ShowDialog();
if (dr == DialogResult.OK)
{
panel1.BackColor = dlg.Color;
customColors = dlg.CustomColors;//this line!
}
I've built a simple example for you, you may try it, thanks!
Kind regards,
Ying-Shen Yu [MSFT]
Microsoft Support Engineer
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2001 Microsoft Corporation. All rights
reserved.
"Tony Lin" <to...@linfamily.org> 写入邮件
news:eJVXrncX...@TK2MSFTNGP12.phx.gbl...