Ok, I’m about googled out. I have made a mistake it would seem, by designing the system before testing to see if it really works. Basically, I am providing a prompt to a color dialog to get a user selected color. I’m using this code:
ColorDialog MyDialog = new ColorDialog();
// Keeps the user from selecting a custom color.
MyDialog.AllowFullOpen = false;
MyDialog.AnyColor = false;
// Allows the user to get help. (The default is false.)
MyDialog.ShowHelp = true;
MyDialog.SolidColorOnly = true;
// Open color selection dialog box
MyDialog.ShowDialog();
functionValue = MyDialog.Color.Name;
function = "highlight";
currentFunctionValue = MyDialog.Color.Name;
functionValue is defined as a string, and that holds the color which was retrieved from the database. For example, “Red”. Later on, I use this to color a cell or row of cells in a datagrid using this code:
if (ruleFunction[j] == "highlight")
{
Color color = Color.FromName(ruleFunctionValues[j]);
grdTransactions.Rows[i].Cells[index].Style.BackColor = color;
}
This works fine if the color name is “Red”, “Blue”, etc. However, some dialog choices returns the value of things like “ff8000” and other hexadecimal representations of the color. I guess this throws off the Color.FromName function, and the cells not only do not have a color, but have messed the text up within the datagrid cells. Is there any way to either make it display the color that was selected with the name like “ff8000”, or exclude those colors from the colorDialog selection screen? I really don’t want to create my own custom dialog with colors if I can help it. I would even go back and change how it’s stored in the database if necessary. Any help would be appreciated!
Thanks!
Instead of storing the name that came back, just store the color object that comes back. Then you can just assign it directly instead of going to and from string values.
Edit: If you can’t store it as a color object, then use the integer value of ToArgb. Then you can load it using the FromArgb method.