Posts

Showing posts from September, 2015

How to change the ForeColor of individual items in a ComboBox in C# Winforms

Image
//SET COMBOBOXBOX PROPERTY TO DRAWMODE =>Ownerdrawfixed or Ownerdravariable
 private void cmbColour_DrawItem(object sender, DrawItemEventArgs e)
        {
            try
            {    
               YourClassName  presenter =new YourClassName();    
                presenter.DrawColourCode(sender, e);
            }
            catch (Exception ex)
            {

                    throw ex;

            }
        }

   public void DrawColourCode(object sender, DrawItemEventArgs e)
        {

//HERR I AM USING DATABASE TO FETCH THE COLOURCODE, ,FOREGROUDCOLOUR //AND BACKGROUNDCOLOUR
            float size = 10;
            System.Drawing.Font myFont;
            string backgroundColorCode = Convert.ToString(((sender as ComboBox).Items[e.Index] as ClassEntityName).BackgroundColourCode);
            // Draw the background of the item.
            e.DrawBackground();
            Brush BrsFore = null;
            // Create a square filled with the item color. Vary the size
       …