namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private TextBox textBox1;
public Form1()
{
InitializeComponent();
textBox1 = new TextBox();
textBox1.Dock = DockStyle.Top;
textBox1.ShortcutsEnabled = false; // 禁用定义的快捷方式。
textBox1.PreviewKeyDown += new PreviewKeyDownEventHandler(textBox1_PreviewKeyDown);
this.Controls.Add(textBox1);
}
private void textBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
switch (e.KeyData)
{
case (Keys.Control | Keys.A):
textBox1.SelectAll();
break;
case (Keys.Control | Keys.C):
textBox1.Copy();
break;
case (Keys.Control | Keys.X):
textBox1.Cut();
break;
case (Keys.Control | Keys.V):
textBox1.Paste();
break;
case (Keys.Control | Keys.Z):
textBox1.Undo();
break;
case (Keys.Control | Keys.L):
textBox1.TextAlign = HorizontalAlignment.Left;
break;
case (Keys.Control | Keys.E):
textBox1.TextAlign = HorizontalAlignment.Center;
break;
case (Keys.Control | Keys.R):
textBox1.TextAlign = HorizontalAlignment.Right;
break;
}
}
}
}
TextBox 控件自定义快捷键
最新推荐文章于 2022-11-10 13:45:12 发布
using System.Windows.Forms;