【发布时间】:2020-01-14 22:38:21
【问题描述】:
我想在以后的部分中利用输入到 TextBox 中的信息
这个程序。该程序将其全部设置在一个表格中,当我键入时
在文本框中输入一些内容并按 Enter 键,它转到第 32 行,
Console.WriteLine,正确并显示引用的部分“进行计算
这里”,但不是在 TextBox 中键入的值 txtFolder。
using System;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
public class MainForm : Form {
private TextBox txtFolder;
// set up the window
public MainForm() {
InitializeComponents();
}
private void InitializeComponents() {
this.Text = "Textbox";
Width = 500;
// get textbox entry
Label sbfldr = new Label();
sbfldr.Location = new Point(10,140);
sbfldr.Size = new Size (315,20);
sbfldr.Text = "Enter something into textbox and press the ENTER key";
this.Controls.Add(sbfldr);
TextBox txtFolder = new TextBox();
txtFolder.Location = new Point(325,139);
txtFolder.KeyUp += getFolder;
txtFolder.Parent = this;
this.Controls.Add(txtFolder);
}
private void getFolder(object sender, KeyEventArgs e) {
if (e.KeyCode == Keys.Enter) {
Console.WriteLine("do calculations here "+txtFolder);
e.Handled = true;
}
}
public class Program {
public static void Main(string[] args) {
Application.Run( new MainForm() );
}
}
}
【问题讨论】:
-
txtFolder.Text:)