简体   繁体   中英

How to get texts form a text file to AutoComplete c#/.net Windows Form

i have created a login form and i am saving username or passwords to a text file useing using System.IO FileStream. And i want to use AutoComplete for username textbox or password textbox.

i want to get username or password in AutoComplete that i saved in text file so that i will not have to put the username ot password in textboxes.

It should show username or password in textbox to select like this (Click to see) http://i49.tinypic.com/rkuats.jpg and http://i46.tinypic.com/21edys1.jpg

What are you developing? If it's a web application, you can use jQuery UI to implement autocomplete for textboxes:

$(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
    });
});

If you are using WPF, you can do it similarly in C#:

 public Window1()
 {
     InitializeComponent();
     List<string> source = new List<string>{/*your source of strings*/};
     TextBoxName.ItemSource = source;
 }

Another method:

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM