这种类型的ComboBox功能怎么实现?(急诊)

空中猎手 2005-05-17 09:14:40
我想在下拉框出来的时候,鼠标移到哪项上,那么这个值就自动显示在Text上,这样怎么做呢?
另外要求ComboxBox的Edit内容还是得充许修改。

附:最终效果实际上应该是这样滴

下拉框项目如下:
今天
明天
后天

那么最终的效果是,鼠标移动到今天上,那么Text的内容自动变成2005-5-17,移动到明天上,那么内容变为2005-5-18......
...全文
123 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Maconel 2005-05-17
  • 打赏
  • 举报
回复
在设置了ComboBox1->ItemIndex = -2;之后,ComboBox1的ItemIndex会等于鼠标下的那个item,edit里也会自动变化,但是不会产生OnSelect事件,如果要将内容变为“2005-5-17”等,可以根据ComboBox1->ItemIndex的值来设置。
Maconel 2005-05-17
  • 打赏
  • 举报
回复
截获combobox的WM_CTLCOLORLISTBOX消息,
然后设置ComboBox1->ItemIndex = -2;即可。
如:
if (Message.Msg == WM_CTLCOLORLISTBOX)
{
ComboBox1->ItemIndex = -2;
}
happyct 2005-05-17
  • 打赏
  • 举报
回复
按照鲨鱼的方法,我试了下,没成功,不过找了个替代的方法,就是有点笨
constantine 2005-05-17
  • 打赏
  • 举报
回复
打鲨鱼
  • 打赏
  • 举报
回复
TCustomComboBox::OnMeasureItem

TCustomComboBox See also
Occurs when an item in a csOwnerDrawVariable combo box needs to be redisplayed.

typedef void __fastcall (__closure *TMeasureItemEvent)(Controls::
TWinControl* Control, int Index, int &Height);
__property TMeasureItemEvent OnMeasureItem = {read=FOnMeasureItem, write=FOnMeasureItem};

Description

When Style is set to csOwnerDrawVariable, the OnMeasureItem event precedes OnDrawItem. Write an OnMeasureItem event handler to specify the height, in pixels, needed to draw an item in the drop-down list.

OnMeasureItem passes three parameters to its event handler:

Control A reference to the combo box containing the item.
Index The index of the item in the Items property.
Height The default height of the item, in pixels.

The event handler can reset the final parameter, Height, to the appropriate value.
空中猎手 2005-05-17
  • 打赏
  • 举报
回复
void __fastcall TfrmMain::NewComboBoxExProc(TMessage & Message)
{
if (Message.Msg == WM_CTLCOLORLISTBOX)
{
cbStudyDate->ItemIndex = -2;
cbStudyDate->Text = GetComboBoxText(cbStudyDate->ItemIndex);
}
OldComboBoxExProc(Message);
}
我现在要求是光标移动某项时,那么Text的值显示另一个串,比如:我移动到今天这项上,那么Text显示20050517。现在按上面的写法是没问题了。但是当我Select时,Text就又会变成"今天"。这个怎么解决?

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧