none
Combobox display member font RRS feed

  • Question

  • Good day

    I have a combobox where you can select a font ,

    then i want to update the font of the box where the font is displayed.

    The problem is that i don't want the selection part of the combobox to be that font,Just the part where it is displayed.

    Any help is appreciated



    Thursday, September 20, 2012 11:28 AM

Answers

  • If I understood correctly, you want to change the font of the text part of the combobox but not the font of the dropdown.

    Maybe it's possible easily with WPF. With Windows.Forms, you cannot set the fonts seperately. You might try putting a textbox in front of the combobox.

    • Marked as answer by Tiaan stassen Friday, September 21, 2012 6:36 AM
    Thursday, September 20, 2012 2:48 PM

All replies

  • Hi,

    what does it mean:

    The problem is that i don't want the selection part of the combobox to be that font. Just the part where it is displayed.

    If we take an item from your comboBox, what type is it? Is it only a string (name, ie: red, black), or its an actual Color class, so it can be directly used?


    Mitja

    Thursday, September 20, 2012 12:40 PM
  • The item they select is string (Font name)

    I want to display that font name in its own font type.

    I managed to do that but i don't want that font for when the users drops down the list.

    Thursday, September 20, 2012 12:55 PM
  • So you need the Color class as a "background" selection, right?

    When users, for example, selects "red", you want to set some text to red. Is that correct?


    Mitja

    Thursday, September 20, 2012 1:02 PM
  • Just the font type
    Thursday, September 20, 2012 1:21 PM
  • As simple as that:

    1. create a new custom class:

        class MyColor
        {
            public string _MyName { get; set; }
            public Color _MyColor { get; set; }
        }


    2. create a new list<T>, where T is this class, and asign data to properties of the class:

                string[] colors = new[] { "red", "green", "blue" };  //list of your colors as strings, put all here!
                List<MyColor> listOfColors = new List<MyColor>();
                foreach (string color in colors)
                {
                    listOfColors.Add(new MyColor { _MyName = color, _MyColor = CreatingColors(color) });
                }
                comboBox1.DataSource = listOfColors;
                comboBox1.DisplayMember = "_MyName";
                comboBox1.ValueMember = "_MyColor";


    3. retreiving color from selected item of comboBox then goes like:

            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                if (comboBox1.SelectedIndex > -1)
                {
                    MyColor mc = comboBox1.SelectedItem as MyColor;
                    if (mc != null)
                    {
                        string name = mc._MyName;
                        Color color = mc._MyColor;  //asign color to what ever now...
                    }
                }
            }

    Hope it helps,

    bye


    Mitja

    • Proposed as answer by Norkk Thursday, September 20, 2012 1:45 PM
    Thursday, September 20, 2012 1:43 PM
  • If I understood correctly, you want to change the font of the text part of the combobox but not the font of the dropdown.

    Maybe it's possible easily with WPF. With Windows.Forms, you cannot set the fonts seperately. You might try putting a textbox in front of the combobox.

    • Marked as answer by Tiaan stassen Friday, September 21, 2012 6:36 AM
    Thursday, September 20, 2012 2:48 PM