怎么在c#中實作點擊一次按鈕就添加一個選單啊,我只能實作點擊一次創建一個,再點擊就沒用了。圖片是老師做的

uj5u.com熱心網友回復:
嗯,win10,vs2019,dell的本子
public Form1()
{
InitializeComponent();
MenuStrip menuStrip = new MenuStrip();
this.Controls.Add(menuStrip);
TextBox textBox = new TextBox()
{
Size = new Size(100, 20),
Location = new Point(20,50)
};
this.Controls.Add(textBox);
Button button = new Button()
{
Size = new Size(120, 25),
Location = new Point(140, 50),
Text = "Add-MenuText"
};
button.Click += (sender, e) =>
{
if (string.IsNullOrEmpty(textBox.Text))
{
MessageBox.Show("Text required");
textBox.Focus();
}
else
{
menuStrip.Items.Add(textBox.Text);
textBox.Clear();
textBox.Focus();
}
};
this.Controls.Add(button);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/97734.html
標籤:C#
上一篇:關于Flowlayoutpanel 設定allowscroll后依舊顯示不全的問題
下一篇:c#操作excel
