Search code examples
c#messagebox

Determine MessageBoxIcon Based on ComboBox


I want to combine a ComboBox's value and a MessageBoxIcon. I want it (basically) to do this:

MessageBox.Show("Text", "Text", MessageBoxButtons.OK, MessageBoxIcon.ComboBox.Value.ToString());

Is this possible? It doesn't have to be done in one line. The text will be either "Warning" or "Error".


Solution

  • Use the Enum.Parse method:

    MessageBox.Show("Text", "Text", MessageBoxButtons.OK,
    (MessageBoxIcon)Enum.Parse(typeof(MessageBoxIcon), ComboBox.Text.ToString());