【发布时间】:2012-08-20 00:19:30
【问题描述】:
private void btnPress_Click(object sender, EventArgs e)
{
String key = ((Button)sender).Text;
InputSimulator.SimulateTextEntry(key);
SendKeys.SendWait(VirtualKeyCode.NUMPAD4.ToString());
}
[DllImport("user32.dll")]
public static extern int SetForegroundWindow(IntPtr hWnd);
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new KeyPress());
}
这东西没有任何帮助。当我单击我的文本框并单击 ont button1 时,此处不会出现 1.. 并且文本框焦点也丢失了..
【问题讨论】:
-
您可以将最后聚焦的文本框保存在 textBox_GotFocus 事件中,并在 btnPress_Click 中简单地附加到其文本。
-
但你不认为这是一种糟糕的编码方法。有那么难做吗?
-
@Sirwani - 你能解释一下按钮点击里面的代码吗?准确地说是第二行和第三行。
-
如果 button1 被按下,则文本为 1,然后将 1 存储在“key”中,然后尝试将此文本模拟到文本框中
-
SendKeys.SendWait(VirtualKeyCode.NUMPAD4.ToString());只是网络上的另一种热门和试用方式
标签: c# winforms keyboard keyboard-events