【发布时间】:2018-01-10 09:47:36
【问题描述】:
我正在 C# 中尝试创建与 AHK 中类似的热键功能。就像在任何视频游戏中一样,您单击一个框,按下热键并注册它。 这就是我试图用 textBox 做的事情:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Keybinder
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
KeyPreview = true;
textBox1.ReadOnly = true;
textBox1.Focus();
}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = "HELLO";
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
char key = e.KeyChar;
string keystring = Char.ToString(key);
textBox1.Text = keystring;
}
}
}
但是,问题是,我需要关闭文本框的基本功能,但我不知道怎么做。例如:光标仍然处于活动状态,我可以突出显示其中的文本。
【问题讨论】:
标签: c# forms textbox autohotkey key-bindings