本文主要是介绍duilib学习------网易云信combo控件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
xml中加人:
<!--combobox-->
<Combo class="list" name="combo" height="30" margin="0,12,0,0" padding="6" bkimage="file='../public/combo/normal.png' corner='5,5,30,5'"/>
(1)BasicForm.h
bool OnComboItemSelected(ui::EventArgs* msg);
ui::Combo *pcombo_;
(2)BasicForm.cpp
bool BasicForm::OnComboItemSelected(ui::EventArgs* msg)
{
if (pcombo_)
{
std::wstring str = std::wstring(L"选择的文本:") + pcombo_->GetText() + std::wstring(L"\n\n");
LPCWSTR result = str.c_str();
OutputDebugString(result);
str = std::wstring(L"当前索引:") + nbase::StringPrintf(L"%d\n\n", pcombo_->GetCurSel());
result = str.c_str();
OutputDebugString(result);
}
return false;
}
void BasicForm::InitWindow()
{
pcombo_ = dynamic_cast<ui::Combo*>(FindControl(L"combo"));
// 增加下拉选项
if (pcombo_)
{
for (auto index = 0; index < 5; ++index)
{
ui::ListContainerElement* pelement = new(std::nothrow) ui::ListContainerElement;
if (pelement)
{
// 设置属性
pelement->SetClass(L"listitem");
pelement->SetFixedHeight(30);
pelement->SetBkColor(L"white");
pelement->SetTextPadding({ 6, 0, 6, 0 });
pelement->SetText(nbase::StringPrintf(L"index %d", index));
pcombo_->Add(pelement);
}
else
{
;
}
}
// 添加结束,设置默认选择第一项
int count = pcombo_->GetCount();
if (0 < count)
pcombo_->SelectItem(0);
// 设置向上弹出下拉选项
pcombo_->SetPopupTop(true);
// 设置监听下拉选项被监听
pcombo_->AttachSelect(nbase::Bind(&BasicForm::OnComboItemSelected, this, std::placeholders::_1));
}
}
这篇关于duilib学习------网易云信combo控件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!