C#-如何对将标签添加到列表框中的文本框进行编程,就像对stackoverflow标签进行编码一样?

时间:2018-08-21 23:09:42

标签: c# windows listbox pc

每次单击Enter时,他都会删除文本框,并将单词的文本添加到列表框中?

1 个答案:

答案 0 :(得分:2)

基本上,以 REALLY BASIC 方式完成您要求的Windows Forms App的代码将是以下内容:

 using System.Windows.Forms;
 namespace WindowsFormsApp1 {
 public partial class Form1 : Form
 {
     public Form1()
     {
         InitializeComponent();
     }

     private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
     {
         if(e.KeyChar == 13) //checks if "enter" was pressed
         {
             listBox1.Items.Add(textBox1.Text);//adds the text to the list
             textBox1.Clear(); //clear the text of the textbox
         }
     }
 } }