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 123
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_KeyPress(object sender,KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
label1.Text = "你按下了〈Enter〉键";
} }
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace 123
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_KeyPress(object sender,KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
label1.Text = "你按下了〈Enter〉键";
} }
}
if(e.KeyChar = '\r') SendKeys.Send("{TAB}");
最近想想,其实有更简单的方法,把Form的KeyPreView设为true,然后在Form的KeyPress中增加下列代码即可:
if (e.KeyChar == '\r')
this.SelectNextControl(this.ActiveControl, true, true, true, true);
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 123{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//textBox1.Text = "你按下了〈Enter〉键";
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
textBox1.Text = "你按下了〈Enter〉键";
else
textBox1.Text = "";
}
}
}