参考书目:C#6.0学习笔记——从第一行C#代码到第一个项目设计(作者周家安)P325
学习内容:textBox和listBox的使用示例,单击添加按钮,可将文本框中的文字增加到列表框中
第一步:窗口布局如下:
为了能使textBox输入中文,将其属性ImeMode设置为on
第二步:添加按钮的响应函数。
主要代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Example11_12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnAddItem_Click(object sender, EventArgs e)
{
//判断TextBox中的文本是否为空
if(string.IsNullOrWhiteSpace(txtInput.Text))