日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

100% .NET Control_自动完成Combobox的XComBo控件(VB.NET)

發布時間:2025/3/15 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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%原創)

??Public?Class?XComBoClass?XComBo
????
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)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。