3
輸入有沒有在C#的方式來猜測用戶將要輸入?例如,當您在Visual Studio中輸入內容並從Fi開始時,File就會作爲答案並提示用戶按Enter鍵輸入。有沒有辦法做到這一點與文本框?猜測哪些用戶將在文本框
輸入有沒有在C#的方式來猜測用戶將要輸入?例如,當您在Visual Studio中輸入內容並從Fi開始時,File就會作爲答案並提示用戶按Enter鍵輸入。有沒有辦法做到這一點與文本框?猜測哪些用戶將在文本框
這實際上取決於您的應用程序的複雜性,但直接的方法是將文本框上的AutoCompleteMode屬性設置爲相關AutoCompleteMode枚舉。來自MSDN鏈接的示例代碼
private void Form1_Load(object sender, EventArgs e)
{
// Create the list to use as the custom source.
var source = new AutoCompleteStringCollection();
source.AddRange(new string[]
{
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
});
// Create and initialize the text box.
var textBox = new TextBox
{
AutoCompleteCustomSource = source,
AutoCompleteMode =
AutoCompleteMode.SuggestAppend,
AutoCompleteSource =
AutoCompleteSource.CustomSource,
Location = new Point(20, 20),
Width = ClientRectangle.Width - 40,
Visible = true
};
// Add the text box to the form.
Controls.Add(textBox);
}
您是否嘗試過搜索'autocomplete'? – Gray
哪種技術? asp.net,mvc,wpf,表單? –
如果您沒有任何自動填充文本框,則可以使用包含可能值的列表框,將用戶類型轉移給它並顯示列表框結果。 –