C++ wxWidgets界面中各类控件的创建、布局和使用

2023-12-27 16:35:28

一、控件的创建

TbaTreeList m_List; //表或树
wxButton m_btnAnas;  //按钮
wxButton m_btnLoc;
wxButton m_btnDetail;
wxButton m_btnSave;

wxImageList m_Img16List;  //图片


void ThkPartSrfAnsDlg::CreateCtrl()
{
	m_List.Create(this, E_CTRL_LIST);
	m_btnAnas.Create(this, E_BTN_ANAS, _T("解析"));
	m_btnLoc.Create(this, E_BTN_LOC,  _T("定位"));
	m_btnDetail.Create(this, E_BTN_DETAIL, _T("明细"));
	m_btnSave.Create(this, E_BTN_SAVE, _T("保存"));

m_List.SetHeader("序号,65;模型,120;个数,50;总系数,70;面积,70");

	m_List.AdjustLayout();
	m_List.SetMinSize({ 500, 310 });
}

二、控件的布局

void ThkPartSrfAnsDlg::AdjustCtrl()
{
	wxBoxSizer* sizeBtn = new wxBoxSizer(wxHORIZONTAL);
	sizeBtn->AddStretchSpacer(20);
	sizeBtn->Add(&m_btnAnas, 20, wxALIGN_CENTER | wxALL, 5);
	sizeBtn->AddStretchSpacer(50);
	sizeBtn->Add(&m_btnLoc, 20, wxALIGN_CENTER | wxALL, 5);
	sizeBtn->AddStretchSpacer(50);
	sizeBtn->Add(&m_btnDetail, 20, wxALIGN_CENTER | wxALL, 5);
	sizeBtn->AddStretchSpacer(50);
	sizeBtn->Add(&m_btnSave, 20, wxALIGN_CENTER | wxALL, 5);
	sizeBtn->AddStretchSpacer(20);

	wxBoxSizer* pMain = new wxBoxSizer(wxVERTICAL);
	pMain->Add(&m_List,200, wxALL | wxEXPAND, 5);
	pMain->Add(sizeBtn, 20, wxALL | wxSTRETCH_NOT, 5);
	SetSizer(pMain);
	SetAutoLayout(true);
	Layout();
}

三、图片的加载

wxBitmap bitmap;

bitmap.LoadFile(_RPIC(bitmap_tree), wxBITMAP_TYPE_BMP);
//bitmap.LoadFile("TREEICON", wxBITMAP_TYPE_BMP);
if (!bitmap.IsOk())
{
	bitmap.Create(400, 16);
}
m_Img16List.Create(16, 16);
m_Img16List.Add(bitmap, wxColor(255, 255, 255));

m_List.SetImageList(&m_Img16List);

文章来源:https://blog.csdn.net/weixin_56446102/article/details/135225382
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。