100% .NET Control_自动完成Combobox的XComBo控件(VB.NET)
生活随笔
收集整理的這篇文章主要介紹了
100% .NET Control_自动完成Combobox的XComBo控件(VB.NET)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
其實這類的文章在國外的技術網站上也有很多,但是都沒有實現combobox的自動下拉.
在這里實現了自動下拉.
在這里我把combobox做成了一個控件(XComBo)來實現功能.它從ComboBox,可以將新建的
工程的繼承改為? Inherits System.Windows.Forms.ComboBox
我認為很關鍵的兩點是API函數SendMessage的調用和KeyPress代碼段e.Handled = True的應用。
If the event is not handled, it will be sent to the operating system for default processing. Set Handled to true to cancel the KeyPress event.
Control's code:(100%原創)
????Inherits?System.Windows.Forms.ComboBox
#Region?"?Windows?Form?Designer?generated?code?"
????Public?Sub?New()Sub?New()
????????MyBase.New()
????????'This?call?is?required?by?the?Windows?Form?Designer.
????????InitializeComponent()
????????'Add?any?initialization?after?the?InitializeComponent()?call
????End?Sub
????'UserControl1?overrides?dispose?to?clean?up?the?component?list.
????Protected?Overloads?Overrides?Sub?Dispose()Sub?Dispose(ByVal?disposing?As?Boolean)
????????If?disposing?Then
????????????If?Not?(components?Is?Nothing)?Then
????????????????components.Dispose()
????????????End?If
????????End?If
????????MyBase.Dispose(disposing)
????End?Sub
????'Required?by?the?Windows?Form?Designer
????Private?components?As?System.ComponentModel.IContainer
????'NOTE:?The?following?procedure?is?required?by?the?Windows?Form?Designer
????'It?can?be?modified?using?the?Windows?Form?Designer.??
????'Do?not?modify?it?using?the?code?editor.
????<System.Diagnostics.DebuggerStepThrough()>?Private?Sub?InitializeComponent()Sub?InitializeComponent()
????????components?=?New?System.ComponentModel.Container
????End?Sub
#End?Region
????Private?Declare?Function?SendMessage()Function?SendMessage?Lib?"user32.dll"?Alias?"SendMessageA"?(ByVal?hwnd?As?Integer,?ByVal?wMsg?As?Integer,?ByVal?wParam?As?Integer,?ByVal?lParam?As?Integer)?As?Integer
????Private?Const?CB_SHOWDROPDOWN?=?&H14F
????Private?Sub?ComboDropdown()Sub?ComboDropdown()
????????SendMessage(Handle.ToInt32,?CB_SHOWDROPDOWN,?1,?0&)
????End?Sub
????Protected?Overrides?Sub?OnKeyPress()Sub?OnKeyPress(ByVal?e?As?System.Windows.Forms.KeyPressEventArgs)
????????Dim?str,?strCurrentText?As?String
????????If?((Asc(e.KeyChar)?=?13)?And?(Asc(e.KeyChar)?=?8))?Then?Exit?Sub
????????ComboDropdown()
????????strCurrentText?=?Mid(Text,?1,?Text.Length?-?SelectedText.Length)?&?CStr(e.KeyChar)
????????str?=?CStr(strCurrentText)
????????Dim?Index?As?Integer?=?FindString(str)
????????If?Index?>=?0?Then
????????????SelectedIndex?=?Index
????????????[Select](str.Length,?Items(Index).length?-?str.Length)
????????????e.Handled?=?True
????????End?If
????End?Sub
End?Class
轉載于:https://www.cnblogs.com/rippleyong/archive/2004/06/30/19780.html
總結
以上是生活随笔為你收集整理的100% .NET Control_自动完成Combobox的XComBo控件(VB.NET)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SYNCHRONIZE_DRAIN的用处
- 下一篇: type A1使用