6
Answers

changed the only color of item selected in combo box by c#

Photo of Zahraa Hazim

Zahraa Hazim

5y
5.8k
1
How do I change the fore color of  item in combo box after item selected .. To alert the user so they are not selected again  ??.....  By c#

Answers (6)

2
Photo of Dinesh Gabhane
76 24.4k 1.7m 5y
Plese check below code
 
  1. public Form1()  
  2.     {  
  3.         InitializeComponent();  
  4.   
  5.         comboBox1.FlatStyle = FlatStyle.Popup;  
  6.   
  7.         comboBox1.DropDown += new EventHandler(comboBox1_DropDown);  
  8.         comboBox1.DropDownClosed += new EventHandler(comboBox1_DropDownClosed);  
  9.     }  
  10.   
  11.     void comboBox1_DropDownClosed(object sender, EventArgs e)  
  12.     {  
  13.         comboBox1.ForeColor = Color.Red;  
  14.     }  
  15.   
  16.     void comboBox1_DropDown(object sender, EventArgs e)  
  17.     {  
  18.         comboBox1.ForeColor = Color.Black;  
  19.     }  
 
0
Photo of Sundaram Subramanian
72 26.4k 1.4m 5y
Lets say 
 
Color color = Color.Blue; // Set this as Global.
 
Whenever the color is changed, set the color in the Global value (color). When the user reset, clear it or rest the color 
0
Photo of Zahraa Hazim
NA 211 5.8k 5y
good morning
 
thank you for information mr. Sundaram Subramanian .
 can you tell me how I keep the color value in a Global Variable ?? can I use another way for solve this topic??
 with regards 
 
0
Photo of Sundaram Subramanian
72 26.4k 1.4m 5y
Keep the color value in a Global Variable, until the user reset. 
0
Photo of Zahraa Hazim
NA 211 5.8k 5y
Thank you very much for your replies
For the first code sent by Mr. Dinesh Gabhane
I applied it but my exact problem is not just how to color the item during the presentation ,
But I want the element previously selected to change the default color to red color, for example, until the user presses a button to restore the previous settings
This code color element after selected during the show only, but when you open the combo box again note that the color back to the previous color .. Is there a way to solve this topic  ???
------------------------------------------------------------------------------------------
As for Mr. Mark Tabor's code, I honestly don't use XAML codes  
With Regards
0
Photo of Mark Tabor
581 2k 486.2k 5y
In the simplest case you can write this in XAML:
 
<ComboBox ItemsSource="{Binding DropDowmItems}" Foreground="Red"> <ComboBox.ItemContainerStyle> <Style TargetType="{x:Type ComboBoxItem}"> <Setter Property="Foreground" Value="Black"/> </Style> </ComboBox.ItemContainerStyle> </ComboBox>
 
I am not sure are you using WPF or normal windows or web forms