你在開發?如果它是一個Web應用程序,你可以使用jQuery UI來實現自動完成的文本框:
$(function() {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
$("#tags").autocomplete({
source: availableTags
});
});
如果您正在使用WPF,你可以做同樣在C#:
public Window1()
{
InitializeComponent();
List<string> source = new List<string>{/*your source of strings*/};
TextBoxName.ItemSource = source;
}
另一種方法:
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);
}
參考來源:http://jqueryui.com/demos/autocomplete/ http://www.c-sharpcorner.com/uploadfile/dpatra/auto-complete-box-in-wpf-toolkit/ – rexcfnghk
我我正在創建一個樣本日誌在窗體中的窗體形式 –
我認爲你可以使用上面顯示的WPF方法類似地執行 – rexcfnghk