2012-09-21 11 views
0

我已經創建了一個登錄表單,我將用戶名或密碼保存到使用using System.IO FileStream的文本文件中。我想爲用戶名文本框或密碼文本框使用自動完成。如何讓文本形成一個文本文件到自動完成c#/ .net Windows窗體

我想在AutoComplete中獲取用戶名或密碼,我保存在文本文件中,這樣我就不必將用戶名ot密碼放在文本框中。

它應該顯示在文本框的用戶名和密碼,選擇這樣的(點擊查看)http://i49.tinypic.com/rkuats.jpghttp://i46.tinypic.com/21edys1.jpg

回答

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

參考來源:http://jqueryui.com/demos/autocomplete/ http://www.c-sharpcorner.com/uploadfile/dpatra/auto-complete-box-in-wpf-toolkit/ – rexcfnghk

+0

我我正在創建一個樣本日誌在窗體中的窗體形式 –

+0

我認爲你可以使用上面顯示的WPF方法類似地執行 – rexcfnghk