[英]Show autocomplete list after calling TextBox.AppendText()
I have a series of buttons in a winforms dialog (on .net4.5) that append snippets of text to a textbox called FieldDescription
, like this:我在 winforms 对话框(在 .net4.5 上)中有一系列按钮,它们将文本片段附加到名为
FieldDescription
的文本框,如下所示:
private void SnippetButton_Click(object sender, EventArgs e)
{
var btn = sender as Button;
FieldDescription.AppendText(btn.Text);
FieldDescription.Focus();
}
The textbox has an autocomplete source, and I would like the autocomplete to open after appending the text.文本框有一个自动完成源,我希望在附加文本后打开自动完成。 The idea is to allow users to easily pre-fill the textbox with the beginning characters of the most used texts.
这个想法是让用户可以轻松地用最常用文本的开头字符预填充文本框。 In many cases this means they just have to select an entry from the autocomplete list after clicking the button, without having to use the keyboard.
在许多情况下,这意味着他们只需在单击按钮后从自动完成列表中选择一个条目,而不必使用键盘。
Is there a way to trigger the autocomplete window after appending the text programmatically like this?有没有办法在像这样以编程方式附加文本后触发自动完成窗口?
Surprisingly I couldn't find a way to do this nicely.令人惊讶的是,我找不到一种方法来很好地做到这一点。
If you can't find a way within .NET you can do it via ap/invoke.如果您在 .NET 中找不到方法,您可以通过 ap/invoke 来完成。
[DllImport("user32.dll", CharSetCharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(IntPtr hWnd, Int32 Msg, IntPtr wParam, IntPtr lParam);
private const int CB_SHOWDROPDOWN = 0x014F;
SendMessage(FieldDescription.Handle, CB_SHOWDROPDOWN, (IntPtr)1, (IntPtr)0);
You can put it into the OnFocus
event.您可以将其放入
OnFocus
事件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.