首页 > 其他 > 详细

自定义自动搜索控件

时间:2015-09-16 19:29:35      阅读:202      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!