c#图形,如何在文本框中输入内容后,点击确定按钮,将文本输入的内容打印出来,在控制台打印就行
展开全部
namespace WinFormWithConsole
{
using System;
using System.Drawing; // 由于该程序本身是控制台程序,所以需要添加System.Drawing组件引用
using System.Windows.Forms; // 需要添加System.Windows.Forms组件引用,
class Program
{
private static Form frmInput=null;
private static System.Windows.Forms.TextBox textBox1 = new TextBox();
private static System.Windows.Forms.Button button1 = new Button();
static void Main(string[] args)
{
frmInput= new Form();
textBox1.Location = new System.Drawing.Point(125, 43);
textBox1.Name = "textBox1";
textBox1.Size = new System.Drawing.Size(120, 21);
textBox1.TabIndex = 0;
button1.Location = new System.Drawing.Point(136, 84);
button1.Name = "button1";
button1.Size = new System.Drawing.Size(98, 31);
button1.TabIndex = 1;
button1.Text = "button1";
button1.UseVisualStyleBackColor = true;
button1.Click += (x, y) =>
{
if (!String.IsNullOrWhiteSpace(textBox1.Text)) {
Console.WriteLine(textBox1.Text.Trim());
}
};
frmInput.Controls.Add(textBox1);
frmInput.Controls.Add(button1);
Application.Run(frmInput);
Console.WriteLine();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |