Windows窗体按钮显示文本框并输入名称以创建新按钮

时间:2013-06-11 06:03:47

标签: c# windows forms button panel

如何在show textbox内执行一个按钮textbox输入名称并按Enter键,然后创建一个名称放在面板中的textbox中的按钮?

1 个答案:

答案 0 :(得分:0)

不幸的是,C#中没有InputMessageBox。 但是你可以使用Interaction.InputBox引用“Microsoft.VisualBasic”和dann。

using Microsoft.VisualBasic;


  // Click-Event
  private void btn_GetName_Click(object sender, EventArgs e)
  {
        string btnTxt = Interaction.InputBox("Title", "Message", "defaultValue", 10, 10);

        Button button1 = new Button();
        button1.Location = new Point(20, 10);
        button1.Text = btnTxt;
        this.Controls.Add(button1);
  }

这是一个非常简单的任务,请在下次使用Google或发布一些代码来调试您的错误。

BTW:StackOverflow中有很多其他解决方案。