CÁC GIẢI PHÁP LẬP TRÌNH C# - Trang 210

210
Chương 6: Windows Form

AutoCompleteComboBox

thành một Class Library Assembly độc lập rồi thêm nó vào hộp công

cụ, thế là bạn có thể thêm nó vào form lúc thiết kế.

using System;

using System.Windows.Forms;

using System.Drawing;

using System.IO;

public class AutoCompleteComboBoxTest : System.Windows.Forms.Form {

// (Bỏ qua phần mã designer.)

private void AutoCompleteComboBox_Load(object sender,

System.EventArgs e) {

// Thêm ComboBox vào form.

AutoCompleteComboBox combo = new AutoCompleteComboBox();

combo.Location = new Point(10,10);

this.Controls.Add(combo);

// Thêm một số từ (từ một file text) vào ComboBox.

FileStream fs = new FileStream("words.txt", FileMode.Open);

using (StreamReader r = new StreamReader(fs)) {

while (r.Peek() > -1) {

string word = r.ReadLine();

combo.Items.Add(word);

}

}

}

}

Liên Kết Chia Sẽ

** Đây là liên kết chia sẻ bới cộng đồng người dùng, chúng tôi không chịu trách nhiệm gì về nội dung của các thông tin này. Nếu có liên kết nào không phù hợp xin hãy báo cho admin.