简体   繁体   English

调用 TextBox.AppendText() 后显示自动完成列表

[英]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.

相关问题 TextBox.AppendText()无法自动滚动 - TextBox.AppendText() not autoscrolling TextBox.Text +=“字符串”; vs TextBox.AppendText(“字符串”); - TextBox.Text += “string”; vs TextBox.AppendText(“string”); 跨类共享TextBox.AppendText()方法的最干净方法是什么? - What is the cleanest way to share a TextBox.AppendText() method across classes? 试图在textbox.AppendText中退格显示一个奇怪的符号 - Trying to do a backspace in textbox.AppendText shows a weird symbol 为什么从我的代码中删除TextBox.AppendText()会更改此处的套接字通信? - Why removig TextBox.AppendText() from my code changes socket communication here? 使用\\ n作为行终止符时,为什么c#textbox.AppendText()换行符会消失? - Why do c# textbox.AppendText() newlines disappear when using \n as line terminator? TextBox和.AppendText()中带有行的奇怪行为-C# - Odd Behaviour with Lines in TextBox and .AppendText() - C# 有没有比AppendText更快的方法来打印到TextBox? - Is there a faster way to print to a TextBox than AppendText? Winforms - 自动完成TextBox不显示结果 - Winforms - AutoComplete TextBox doesn't show results 自动填充文本框不会在单击文本框内显示结果 - Autocomplete textbox don't show result inside clicking of textbox
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM