【问题标题】:How to get texts form a text file to AutoComplete c#/.net Windows Form如何从文本文件中获取文本到 AutoComplete c#/.net Windows Form
【发布时间】:2012-09-21 04:16:06
【问题描述】:

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

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

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

【问题讨论】:

    标签: c# .net autocomplete io


    【解决方案1】:

    你在开发什么?如果是 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);
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 2011-01-24
    • 2012-09-27
    • 2016-11-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多