⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 faq57.htm

📁 C++builder学习资料C++builder
💻 HTM
字号:


<HTML>

<HEAD>

   <TITLE>Force a ComboBox to drop down</TITLE>

   <META NAME="Author" CONTENT="Harold Howe">

</HEAD>

<BODY BGCOLOR="WHITE">



<CENTER>

<TABLE  BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH="640">



<TR>

<TD>

<H3>

Force a ComboBox to drop down

</H3>

<P>

To tell you the truth, I decided that this would be a good FAQ addition because

I see this question pop up frequently in MFC FAQ's, newsgroups, and discussion

boards (MFC groups are a good place to learn about the API, since MFC doesn't

encapsulate a whole heck of a lot). However, while researching how to force a

<TT>ComboBox</TT> to drop down in C++Builder, I realized that this is so simple

that it probably shouldn't be an FAQ. Oh well.

</P>

<P>

To drop a <TT>ComboBox</TT> from code, simply set the <TT>DroppedDown</TT>

property of the <TT>ComboBox</TT> to true. Here is some code:

</P>

<pre>

<b>void</b> <b>__fastcall</b> TForm1<b>:</b><b>:</b>Button1Click<b>(</b>TObject <b>*</b>Sender<b>)</b>

<b>{</b>

    ComboBox1<b>-></b>DroppedDown <b>=</b> <b>true</b><b>;</b>

<b>}</b>

</pre>

<P>

<B>Note:</B> The <TT>DroppedDown</TT> property also works in reverse. If you need

to check if a <TT>ComboBox</TT> is dropped down, you can read the <TT>DroppedDown</TT>

property. It will be true if the <TT>ComboBox</TT> is dropped down.

</P>

<P>

<B>Note:</B> The write method of the <TT>DroppedDown</TT> property works by sending a

message to the window handle of the <TT>ComboBox</TT>. Just in case your curious, here is

what the VCL code looks like (pascal converted to C++):

</P>

<pre>

<b>void</b> <b>_fastcall</b> TCustomComboBox<b>:</b><b>:</b>SetDroppedDown<b>(</b><b>bool</b> Value<b>)</b>

<b>{</b>

    <font color="navy">// NOTE: must cast bool to pass Value as the WPARAM</font>

    <font color="navy">//       of the message. The VCL actually casts to LongInt.</font>

    SendMessage<b>(</b>Handle<b>,</b> CB_SHOWDROPDOWN<b>,</b> <b>(</b>WPARAM<b>)</b>Value<b>,</b> <font color="blue">0</font><b>)</b><b>;</b>

<b>}</b>

</pre>



</TD> </TR>



</TABLE>

</CENTER>

</BODY>

</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -