如何让文本形成一个文本文件到自动完成c#/ .net Windows窗体
问题描述:
我已经创建了一个登录表单,我将用户名或密码保存到使用using System.IO
FileStream的文本文件中。我想为用户名文本框或密码文本框使用自动完成。如何让文本形成一个文本文件到自动完成c#/ .net Windows窗体
我想在AutoComplete中获取用户名或密码,我保存在文本文件中,这样我就不必将用户名ot密码放在文本框中。
它应该显示在文本框的用户名和密码,选择这样的(点击查看)http://i49.tinypic.com/rkuats.jpg和http://i46.tinypic.com/21edys1.jpg
答
你在开发?如果它是一个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