using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; namespace Demo { public partial class AutoText : UserControl { private string _procValue; public string ProcValue { get { return _procValue; } set { _procValue = value; } } //定义委托 public delegate void AutoSrchHandle(object sender, EventArgs e); //定义事件 public event AutoSrchHandle AutoSearched; public AutoText() { InitializeComponent(); BindListBox(); } void BindListBox() { lbStation.Items.Add("安徽"); lbStation.Items.Add("北京"); lbStation.Items.Add("重庆"); lbStation.Items.Add("上海"); } private void tbProc_MouseEnter(object sender, EventArgs e) { lbStation.Visible = true; } private void tbProc_KeyUp(object sender, KeyEventArgs e) { TextBox eObj = sender as TextBox; //事件源对象 if (e.KeyCode == Keys.Enter) { lblMsg.Text = eObj.Text; } else { ProcValue = tbProc.Text; lblMsg.Text = ProcValue; } } private void lbStation_MouseMove(object sender, MouseEventArgs e) { ListBox eObj = sender as ListBox; eObj.SelectedIndex = eObj.IndexFromPoint(e.Location); } } }
时间: 2024-10-29 19:08:48