?? 2482.html
字號:
<HTML>
<HEAD>
<TITLE> HOWTO: Search a ListBox Control Quickly </TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LEFTMARGIN="0" TOPMARGIN="0">
<FONT FACE="Verdana, Arial, Helvetica" SIZE="2">
<!--DOCBODY_START-->
<TABLE width=602 CELLPADDING=5 CELLSPACING=5 BORDER=0>
<!--DOCTITLE_START-->
<TR>
<TD width=602 align="left">
<H1>Microsoft Knowledge Base</H1>
</TD>
</TR>
<TR>
<TD height=30 width=602 align=left>
<H2>HOWTO: Search a ListBox Control Quickly</H2>
</TD>
</tr>
<tr>
<TD WIDTH="125" ALIGN="left">
<A STYLE="Small">
Last reviewed: July 15, 1997
<BR>
Article ID: Q161161</A>
</TD>
</TR>
<!--DOCTITLE_END-->
<tr>
<td width=602 COLSPAN=2>
<FONT FACE="Verdana, Arial, Helvetica" SIZE=2>
The information in this article applies to:
<UL><LI>Microsoft Visual Basic Control Creation, Learning, Professional, and
Enterprise Editions for Windows, version 5.0
</UL>
<P>
<P><h2>SUMMARY</h2>
<P>
A popular item in a user interface is to "link" a text box to a list box so
the nearest match in the list box is selected when the user types text into
the text box. This technique can be implemented using pure Visual Basic
code, but the Windows API provides a quicker and easier way to do this.
<P>
<P><h2>MORE INFORMATION</h2>
<P>
The technique calls the Windows API SendMessage function using the
LB_FINDSTRING message for a list box to locate a partial match for a string
in the list box. SendMessage requires the following parameters:
<P>
<PRE> SendMessage(hWnd, LB_FINDSTRING, wParam, lParam) where
hWnd - is the hWnd of the list box.
wParam - is an integer that specifies the starting point for the
search. Use -1 to search the whole list box.
lParam - is a long pointer to the string to find.
</PRE><h3>Step-by-Step Example</h3>
<OL><P><LI>Start a new Standard EXE project. Form1 is added by default.
<P><LI>Add a TextBox control (Text1) and a ListBox control (List1) to Form1.
<P><LI>Add the following code to the General Declarations section of Form1:
<P>
<P><PRE> Const LB_FINDSTRING = &H18F
Private Declare Function SendMessage Lib "User32" _
<PRE></PRE> Alias "SendMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Integer, _
ByVal wParam As Integer _
lParam As Any) As Long
Private Sub Form_Load()
List1.Clear
List1.AddItem "Apples"
List1.AddItem "Banana"
List1.AddItem "Bread"
List1.AddItem "Break"
Text1.Text = ""
End Sub
Private Sub Text1_Change()
List1.ListIndex = SendMessage(List1.hWnd, LB_FINDSTRING, -1, _
ByVal CStr(Text1.Text))
End Sub
</PRE><P><LI>Press the F5 key to run the program. Typing text into the text box
selects the first item in the list box which matches the text in the
text box.
</OL>
</FONT>
</TD>
</TR>
</table>
<P>
<!--DOCBODY_END-->
</FONT>
</BODY>
</HTML>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -