Search code examples
c#winformsmessagebox

Dropdown/select inside messagebox in winforms


I would like to have a dropdown/select thing inside my msgbox in c#. Like this one

But to select color theme.

I have tried the following

string[] items = {"Black", "White", "Red", "Green", "Blue"};
string msg = "Select one color theme you like to have active", items;
string title = "Select color theme";
messagebox buttons = MessageBoxButtons.YesNo;
DialogResult result;
result = MessageBox.Show(msg, title, buttons);

But its not working. Do u know any solution to this?


Solution

  • MessageBox is a foraign class where you not can add additional controls. You have to build the Control by yourself.

    var form = new Form(); // or control how you like
    var dropDown = new ComboBox();
    // some dropdown settings ....
    string[] installs = new string[]{"Typical", "Compact", "Custom"};
    dropDown .Items.AddRange(installs);
    form.Controls.Add(dropDown);
    
    // start/show the control
    form.Show();
    

    ComboBox Docu