码迷,mamicode.com
首页 > 其他好文 > 详细

自定义自动搜索控件

时间:2015-09-16 19:30:43      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

技术分享
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);
        }
    }
}
View Code

 

自定义自动搜索控件

标签:

原文地址:http://www.cnblogs.com/windy2008/p/4813997.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!