以焦点显示文本框自动完成 [英] Show textbox autocomplete on focus

查看:78
本文介绍了以焦点显示文本框自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有一个使用C#构建的Windows应用程序.我想在文本框获得焦点后立即打开自动完成建议.
我不想使用任何自定义控件.我想将windows.form文本框控件与AutoCompleteMode等属性一起使用,并希望明确提及此行为.

设置文本框的自动完成属性,一旦您开始输入,它将打开自动完成列表. 但是我的要求是,一旦文本框获得焦点,就应该打开自动完成列表.

希望我已经阐明了我的要求.


谢谢
Nishant

Hello,

I have a windows application build up using C#. I want to open autocomplete suggestions as soon as textbox gets focus.
I don''t want to use any custom control. I want to use windows.form textbox control with properties like AutoCompleteMode and so on, and want to explicitly mention this behavior.

Set autocomplete properties for textbox and as soon as you start typing it opens the list for autocomplete. But my requirement is as soon as textbox gets focus it should open the autocomplete list.

Hope I have clarified my requirements.


Thank you,
Nishant

推荐答案

正在回答的后续问题:
但是我的要求是,一旦文本框获得焦点,它就应该打开自动完成列表.希望我已经阐明了我的要求.
这不是自动完成的工作方式.如果需要显示所有列表,请使用System.Windows.Forms.ComboBox-它可以完全执行您想要的操作(您可能需要处理GotFocus).

至于自动完成功能,在您键入任何内容之前不应该显示列表,这会违反自动完成功能的目的.该列表取决于用户键入的内容,并且该列表可以随键入的每个字符而变化.

(您可能想使用System.Windows.Forms.SendKeys模拟键入,但是我强烈建议避免使用它.要记录一下:在您的GotFocus甚至处理程序中,您可以人为地转到编辑缓冲区的末尾并模拟键入一个空格,然后按退格键;它会显示该列表,就好像用户只是在缓冲区中输入了字符一样,但是……帮自己一个忙:不要触摸已经很好的自动完成功能!您的要求根本是错误的;不要破坏好东西.) br/>
-SA
Answering follow-up question:
But my requirement is as soon as textbox gets focus it should open the autocomplete list. Hope I have clarified my requirements.
This is not how auto-complete works. If you need to show all list, use System.Windows.Forms.ComboBox — it can do exactly what you want (you may want to handle GotFocus).

As to auto-complete, it is not supposed to show a list before you type anything, it would defeat the purpose of the auto-complete. The list depends on what the user types, and the list can change on every character typed.

(You may want to simulate typing using System.Windows.Forms.SendKeys but I strongly recommend avoiding it. For a record: in your GotFocus even handler you could artificially go to the end of edit buffer and simulate typing a blank space followed by backspace; it would show the list as if the user just typed characters already in buffer, but… do yourself a favor: don''t touch already good auto-complete functionality! Your requirement is simply wrong; don''t spoil good thing.)

—SA



这篇关于以焦点显示文本框自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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