如何在winform项目中以编程方式创建ToolStripDropDown
?我想将此项与TextBox
相关联(显示最后的条目),并在点击Button
时显示。
它应该在红线上:
编辑:我实际上有:
Class MyClass : UserControl
{
//Created in designer :
// Button buttonName;
// TextBox textboxName;
// List<String> lastNames;
// I want to create
ToolStripDropDown toolStripName;
public MyClass ()
{
toolStripName = new ToolStripDropDown();
toolStripName.OwnerItem = textboxName; // Want to define the textbox as owner
buttonName.Click += ButtonName_Click;
toolStripName.Items = lastNames; // I want to display the last names saved
}
private void ButtonName_Click(object sender, EventArgs e)
{
toolStripName.Show();
}
}
此代码不起作用。我从未使用过ToolStripDropDown
而且我不知道如何使用它。