Hello,
I have a combo box which lists all the known windows color. I want the selected color combo box color stored and applied to a string in another location.
The following method adds color to a combo box I have in a form -
private void _tlpMain_Paint(object sender, PaintEventArgs e)
{
foreach (System.Reflection.PropertyInfo prop in typeof(Color).GetProperties())
{
if (prop.PropertyType.FullName == "System.Drawing.Color")
_cmbgroupcolor.Items.Add(prop.Name);
String groupcolor = (string)_cmbgroupcolor.SelectedItem; //store color
}
In the last line I am trying to store the color in a variable.
In another class, I want to call this color -
node.ForeColor = groupcolor; //add color to text
I am getting an error saying the "groupcolor" is not found in the current context. I need to somehow make it public so this other class can find it. They are in the same namespace.
Thank you.
Loading
VulpesPosted May 8, 2014, 7:08 AM
So, I think we're going to have to try some general reasoning here.
Firstly, are you sure that the node whose ForeColor you're changing is actually visible and doesn't need to be added to the appropriate node collection or to have its Visible property set to true first?
If you are sure about this, then is it possible that there could be some other code which is setting the ForeColor property back to it previous value before or shortly after it's displayed?
Agile DeveloperPosted May 8, 2014, 6:18 AM
VulpesPosted May 7, 2014, 10:48 AM
Can you upload to a different file sharing site or just post the relevant code.
Agile DeveloperPosted May 6, 2014, 10:43 PM
Agile DeveloperPosted May 6, 2014, 10:25 PM
VulpesPosted May 5, 2014, 5:25 AM
What's 'node' here - a TreeNode may be?
Agile DeveloperPosted May 4, 2014, 9:45 PM
VulpesPosted May 4, 2014, 7:12 PM
Agile DeveloperPosted May 4, 2014, 6:35 PM
VulpesPosted May 4, 2014, 6:04 PM
Agile DeveloperPosted May 4, 2014, 2:17 PM
I am using the following link -
http://www.c-sharpcorner.com/UploadFile/renuka11/using-a-combobox-to-select-colors/
It basically told me to do the following -
string groupcolor = _cmbgroupcolor.SelectedItem.ToString();
node.ForeColor = Color.FromName(groupcolor);
I switched my other methods from private to public, but I still get the error message - The name "_cmbgroupcolor" is not in current context.
Ranjit PowarPosted May 4, 2014, 2:04 PM