发送按键其它控制 [英] Send keystroke to other control
本文介绍了发送按键其它控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
轻松一为你们。
我有一个列表框顶部的文本框。
I have a textbox on top of a listbox.
文本框是使用在列表框中过滤疗法的数据。
The textbox is use to filter ther data in the listbox.
所以...当文本框中的用户类型,我想陷阱的下/上/下页/翻页按键,并将其fowarding到列表框中。
So... When the user type in the textbox, I would like to "trap" the down/up/pagedown/pageup keystrokes and fowarding them to the listbox.
我知道我可以使用Win32 API和发送WM_KEYDOWN消息。但是,有必须有一些.NET的方式来做到这一点。
I know I could use the Win32 API and send the WM_KeyDown message. But there's must be some .NET way to do this.
推荐答案
SendKeys.Send()方法。
SendKeys.Send() Method.
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
listBox1.Focus();
SendKeys.Send(e.KeyChar.ToString());
}
下面是代码,通过它,你可以选择一个列表项。
Here is code through which you can select a list item.
private void Form1_Load(object sender, EventArgs e)
{
textBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
textBox1.AutoCompleteSource=AutoCompleteSource.CustomSource;
string[] ar = (string[])(listBox1.Items.Cast<string>()).ToArray<string>();
textBox1.AutoCompleteCustomSource.AddRange(ar);
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
listBox1.Text = textBox1.Text;
}
这篇关于发送按键其它控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文