Windows窗体 - 开放的建议设置自动完成源后编程方式列表 [英] Windows Forms - Open suggestions list programatically after setting the autocomplete source

查看:180
本文介绍了Windows窗体 - 开放的建议设置自动完成源后编程方式列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的窗户形式的文本框为此我在自动完成配置。我带来的建议动态地从Web serivce的用户类型。这是通过一个背景工人完成。

I'm having a textbox in my windows form for which I'm having autocomplete configured. I'm bringing the suggestions dynamically as the user types from a web serivce. This is done by a background worker.

设置自动完成源我怎么能打开该文本编程的建议后? (有什么样的特性,我们对组合框 - DroppeDown)

After setting the autocomplete source how can I open the suggestions of that textbox programatically? (Something like a property we have for combobox - DroppeDown)

推荐答案

您的选项有:


  1. 使用一个哈克的解决方案

  2. 使用纯C#自动完成控制(例如,写自己的或用别人的)

  3. 开关组合框

您可以找到#2你自己的#3。我认为,#2是最好的选择。但是,阅读,如果你想要做的#1:

You can find #2 and #3 on your own. I think #2 is the best option. However, read on if you want to do #1:

一个干净的解决方案,你问什么不存在。我自动完成的理解是,它是一个COM对象,可能是最初建的Internet Explorer(如间谍++窗口在其层次结构中的Internet Explorer的称号)。总之,自动完成挂接到从编辑控件的WndProc事件。它填充,并显示在收到通知的事件,如KEY_DOWN。名单

A clean solution to what you are asking for doesn't exist. My understanding of autocomplete is that it is a COM object, probably originally built for Internet Explorer (as the Spy++ window has "Internet Explorer" title in its hierarchy). Anyway, the autocomplete hooks into the WndProc events from the editing control. It populates and displays the list when it receives notifications events such as KEY_DOWN.

例如,假设你有一个自动完成至少有一个单词以字母A开始。您可以强制自动完成通过发送POST消息到文本框出现:

For example, suppose you have an autocomplete with at least one word starting with the letter 'A'. You can force the autocomplete to appear by sending a POST message to the TextBox:

//host.Text = "A"; // does not work
PostMessage(textbox.Handle, WM_KEYDOWN, VK_A, 0); // works (see SendKey method below)

[DllImport("user32.dll")]
static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, int wParam, int lParam);


// only works once the Handle has been assigned
public void Show() {
    ShowWindow(Handle, SW_SHOWNOACTIVATE);
}

// e.g. VK_A = 0x41, VK_SPACE = 20;
public void SendKey(int VK_KEY) {
    PostMessage(Host.Handle, 0x100, VK_KEY, 0);
    System.Threading.Tasks.Task.Run((Action) delegate {
        Thread.Sleep(10); // small delay required
        Host.BeginInvoke((Action) delegate {
            Show();
        });
    });
}

据我所知,这是无法直接控制的自动完成的内容。然而,在另一个线程计算器(现在不能找到它),得到的答复是,以preFIX用空格每一个字,让他们都拥有共同的preFIX,然后修剪后的价值。

As far as I know, it's not possible to directly control the contents in the autocomplete. However, in another stackoverflow thread (can't find it now), the answer was to prefix each word with a space so that they all shared a common prefix, and then trim the value afterwards.

您还可以强制自动完成显示时不输入任何内容,但不幸的是这将是空的。例如:

You can also force the autocomplete to appear without typing anything, but unfortunately it will be empty. For example:

const int SW_SHOWNOACTIVATE = 4;
IntPtr p = ...; // handle to Autocomplete window
int width = 400;
int height = 200;
SetWindowPos(p, IntPtr.Zero, -5, 0, width, height, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
ShowWindow(p, SW_SHOWNOACTIVATE);

您可以了解如何在这里得到手柄参考:组合框下拉下宽上建议

You can find out how to get the handle reference here: Combo box drop down width on suggest

即使一旦你的手柄,也没有直接或间接指向其拥有的编辑控制权。在上面的超链接,以确定编辑控制的唯一方法就是听信首次显示自动完成,然后检查每个控件看到它包含用于控制在屏幕上边框的。

Even once you have the handle, there is no direct or indirect link to its owning editing control. In the hyperlink above, the only way to determine the editing control is to listen for the first time the autocomplete is displayed, and then check each control to see which control's on screen bounding box contains it.

这篇关于Windows窗体 - 开放的建议设置自动完成源后编程方式列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆