惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - RichardChoi

C#农历组件 - 修正版 - RichardChoi C#应用程序控制Excel工作簿操作-基本 C#应用程序控制Word文档操作-基本 对System Analysis and Design的课程设计的一些总结 同学Tomholmes对SAD课程设计的需求分析 System Analysis & Design 课程设计题目(英文) Visual Paradigm试用 - 不错的UML建模和代码生成工具 关于UML建模工具和项目管理工具的问题 NOW VS2005 Beta2 is really on installation process 对于Software Architecture和System Analysis比较的看法 SSITE发放VS2005 Beta2 杂篇(一) 突然醒悟 - 两年前的文章 NETCAFE - 两年前写的 等待.... VS2005 Beta2 VS2005 Beta2新信息 Now Installing VS2005 Beta2 VS2005 Beta2 is coming! 求System Analysis and Design的学习电子书和相关资料
C# SuperCombox组件
RichardChoi · 2005-05-22 · via 博客园 - RichardChoi

缓存内容,根据输入筛选结果

  1using System;
  2using System.Collections;
  3using System.ComponentModel;
  4using System.Drawing;
  5using System.Data;
  6using System.Windows.Forms;
  7
  8namespace NetBee.Infrastructure
  9{
 10    /// <summary>
 11    /// SuperComboBox 的摘要说明。
 12    /// </summary>

 13    public class SuperComboBox : System.Windows.Forms.ComboBox
 14    {
 15        /// <summary> 
 16        /// 必需的设计器变量。
 17        /// </summary>

 18        private System.ComponentModel.Container components = null;
 19
 20        private ArrayList _items=new ArrayList();
 21        private string cache;
 22
 23        public SuperComboBox()
 24        {
 25            // 该调用是 Windows.Forms 窗体设计器所必需的。
 26            InitializeComponent();
 27
 28            // TODO: 在 InitializeComponent 调用后添加任何初始化
 29        }

 30
 31        public void AddItemIn()
 32        {
 33            if(this._items.Count>0)
 34            {
 35                if(!this._items.Contains(this.Text) && this.Text!="")
 36                {
 37                    this._items.Add(this.Text);
 38                }

 39            }

 40            else
 41            {
 42                if(this.Text!="")
 43                {
 44                    this._items.Add(this.Text);
 45                }

 46            }

 47        }

 48
 49        public int GetItemsCount()
 50        {
 51            return this._items.Count;
 52        }

 53
 54        /// <summary> 
 55        /// 清理所有正在使用的资源。
 56        /// </summary>

 57        protected override void Dispose( bool disposing )
 58        {
 59            if( disposing )
 60            {
 61                if(components != null)
 62                {
 63                    components.Dispose();
 64                }

 65            }

 66            base.Dispose( disposing );
 67        }

 68
 69        #region 组件设计器生成的代码
 70        /// <summary> 
 71        /// 设计器支持所需的方法 - 不要使用代码编辑器 
 72        /// 修改此方法的内容。
 73        /// </summary>

 74        private void InitializeComponent()
 75        {
 76            // 
 77            // SuperComboBox
 78            // 
 79            this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.SuperComboBox_KeyPress);
 80            this.TextChanged += new System.EventHandler(this.SuperComboBox_TextChanged);
 81
 82        }

 83        #endregion

 84
 85        private void SuperComboBox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
 86        {
 87            if(e.KeyChar=='\r')
 88            {
 89                this.DroppedDown=false;
 90                this.Text=this.cache;
 91                //this.DoSearch();
 92            }

 93
 94            if(char.IsControl(e.KeyChar))
 95            {
 96                if(e.KeyChar=='\b')
 97                {
 98                    this.DroppedDown=false;
 99                    this.Text=this.cache;
100                }

101            }

102        }

103
104        public void ShowList()
105        {
106            this.DroppedDown=true;
107        }

108
109        public void HideList()
110        {
111            this.DroppedDown=false;
112        }

113
114        public ArrayList GetFilteredList()
115        {
116            this.Items.Clear();
117
118            ArrayList newArrayList=new ArrayList();
119            newArrayList.Clear();
120            foreach(string str in this._items)
121            {
122                if(str.Length>0)
123                {
124                    if(str.IndexOf(this.Text)==0 && (!str.Equals(this.Text)))
125                    {
126                        newArrayList.Add(str);
127                    }

128                }

129            }

130            return newArrayList;
131        }

132        
133
134        private void SuperComboBox_TextChanged(object sender, System.EventArgs e)
135        {
136            this.cache=this.Text;
137            if(this.Text!="")
138            {
139                object[] al=this.GetFilteredList().ToArray();
140                if(al.Length>0)
141                {
142                    this.AddItemsCore(al);
143                    this.ShowList();
144                    if(this.cache!="")this.Text=this.cache;
145                    this.SelectionStart=this.Text.Length+1;
146                }

147                else
148                {
149                    if(this.DroppedDown==true)
150                    {
151                        this.HideList();
152                        this.Focus();
153                        this.SelectionStart=this.cache.Length;
154                    }

155                    else
156                    {
157                        this.SelectionStart=this.Text.Length+1;
158                    }

159                }
                    
160            }

161            
162        }

163    }

164}

165


Posted on 2005-05-22 22:05  RichardChoi  阅读(639)  评论(0)    收藏  举报