简体   繁体   English

如何获取文本形式的文本文件到自动完成c#/。net Windows窗体

[英]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. 我已经创建了一个登录表单,并且正在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. 我想获取保存在文本文件中的自动完成功能中的用户名或密码,这样我就不必在文本框中输入用户名ot密码。

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 它应该在文本框中显示用户名或密码,以进行此类选择(单击以查看) http://i49.tinypic.com/rkuats.jpghttp://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: 如果是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
    });
});

If you are using WPF, you can do it similarly in C#: 如果您使用的是WPF,则可以在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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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