-1 c# user-interface textbox winforms
我正在尝试用C#学习GUI编程,我对C#中TextBox的默认代码有以下问题:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication34
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
// Textbox programming goes here
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在,当我想尝试与TexBox编程有点不同的东西时,类似于这段代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication20
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
//
// Detect the KeyEventArg's key enumerated constant.
//
if (e.KeyCode == Keys.Enter)
{
MessageBox.Show("You pressed enter! Good job!");
}
else if (e.KeyCode == Keys.Escape)
{
MessageBox.Show("You pressed escape! What's wrong?");
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我无法运行代码,因为TextBox的状态是
textBox1_KeyDown
Run Code Online (Sandbox Code Playgroud)
而不是默认的
textBox1_TextChanged
Run Code Online (Sandbox Code Playgroud)
现在我的问题是,如何将TextBox事件处理程序从默认事件处理程序更改为另一个?