0

我创建了一个登录表单,我正在使用using System.IOFileStream 将用户名或密码保存到一个文本文件中。我想对用户名文本框或密码文本框使用自动完成。

我想在保存在文本文件中的自动完成中获取用户名或密码,这样我就不必将用户名和密码放在文本框中。

它应该在文本框中显示用户名或密码以像这样选择(点击查看)http://i49.tinypic.com/rkuats.jpghttp://i46.tinypic.com/21edys1.jpg

4

1 回答 1

0

你正在研发什么?如果它是一个 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);
}
于 2012-09-21T04:27:32.113 回答