首页 > 解决方案 > Winforms中的消息框内的下拉/选择

问题描述

我想在 c# 的 msgbox 中有一个下拉/选择的东西。像这个

但要选择颜色主题。

我试过以下

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);

但它不起作用。你知道有什么解决办法吗?

标签: c#winformsmessagebox

解决方案


MessageBox 是一个外国类,您不能在其中添加其他控件。您必须自己构建控件。

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();

组合框文档


推荐阅读