日期:2014-05-18 浏览次数:20699 次
List<string> l; ListBox list = new ListBox(); Dictionary<int, string> dic = new Dictionary<int, string>(); public Form1() { InitializeComponent(); } private void comboBox1_TextChanged(object sender, EventArgs e) { list.Items.Clear(); this.Controls.Add(list); Point p = new Point(); p = comboBox1.Location; list.Location = new Point(p.X, p.Y + 21); list.Size = new Size(134, 80); list.HorizontalScrollbar = true; list.Enabled = true; list.Items.Add("@qq.com"); list.Items.Add("@163.com"); list.Items.Add("@126.com"); list.Items.Add("@yahoo.com"); list.Items.Add("@sina.com"); list.Items.Add("@msn.com"); if (comboBox1.Text.Contains(".com")) { this.Controls.Remove(list); return; } if (comboBox1.Text == "") { this.Controls.Remove(list); } else { for (int i = 0; i < list.Items.Count; i++) { string email = comboBox1.Text; if (email.Contains("@")) { for (int n = 0; n < list.Items.Count; n++) { list.Items[n] = dic[n]; } int sum = email.IndexOf("@", 0); if (comboBox1.Controls.Count - 1 > sum) { if (comboBox1.Controls.Count - sum == 2) { ShowInfo(email, sum, 1); } else if (comboBox1.Controls.Count - sum == 3) { ShowInfo(email, sum, 2); } else { list.Items.Clear(); for (int k = 0; k < l.Count; k++) { list.Items.Add(l[k]); } } } break; } list.Items[i] = email + list.Items[i]; if (dic.ContainsKey(i)) { dic[i] = list.Items[i].ToString(); } else { dic.Add(i, list.Items[i].ToString()); } } } list.MouseDoubleClick += new MouseEventHandler(list_MouseDoubleClick); } private void ShowInfo(string email, int sum, int i) { string s = email.Substring(sum + i, 1); l = new List<string>(); for (int m = 0; m < list.Items.Count; m++)