我正在使用外部 XRC 方法通过 wxFormBuilder 实现我的用户界面。
我正在尝试以这种方式实现从 wxStaticBoxSizer 悬挂的一组面板:
MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size) {
wxXmlResource::Get()->LoadFrame((wxFrame*)this, (wxWindow*)NULL , wxT("MyFrame1"));
wxStaticBoxSizer* almacenador = (wxStaticBoxSizer*)FindItem(XRCID("Contenedor"));
if (!almacenador){
cout << "Error cargando sizer!" << endl << flush;
}
wxXmlResource::Get()->LoadPanel( (wxWindow*)almacenador , wxT("MyPanel6"));
wxXmlResource::Get()->LoadPanel( (wxWindow*)almacenador , wxT("MyPanel6"));
wxXmlResource::Get()->LoadPanel( (wxWindow*)almacenador , wxT("MyPanel6"));
SetTitle(title);
SetIcon(wxICON(appicon));
SetSize(size);
SetPosition(pos);
Show(true);
}
从“主”函数加载资源的位置
wxXmlResource::Get()->Load("rc/resource2.xrc");
线。启动我的程序时它可以工作,因为我在任何地方都看不到这三个面板。
这是我的 XRC 文件:
主框架:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1">
<object class="wxFrame" name="MyFrame1">
<style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style>
<size>283,401</size>
<title></title>
<centered>1</centered>
<aui_managed>0</aui_managed>
<object class="wxPanel" name="m_panel1">
<style>wxTAB_TRAVERSAL</style>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="sizeritem">
<option>0</option>
<flag>wxEXPAND</flag>
<border>5</border>
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<option>0</option>
<flag>wxALL|wxALIGN_BOTTOM</flag>
<border>5</border>
<object class="wxStaticText" name="m_label_Nombre1">
<label>Nombre</label>
<wrap>-1</wrap>
</object>
</object>
<object class="sizeritem">
<option>1</option>
<flag>wxEXPAND|wxTOP|wxRIGHT|wxLEFT</flag>
<border>5</border>
<object class="wxTextCtrl" name="m_text_Nombre">
<value></value>
</object>
</object>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALIGN_TOP|wxEXPAND</flag>
<border>5</border>
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<option>0</option>
<flag>wxALL|wxALIGN_BOTTOM</flag>
<border>5</border>
<object class="wxStaticText" name="m_label_Apellidos">
<label>Apellidos</label>
<wrap>-1</wrap>
</object>
</object>
<object class="sizeritem">
<option>1</option>
<flag>wxTOP|wxRIGHT|wxLEFT</flag>
<border>5</border>
<object class="wxTextCtrl" name="m_text_Apellidos">
<value></value>
</object>
</object>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxEXPAND</flag>
<border>5</border>
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<option>0</option>
<flag>wxALL|wxALIGN_BOTTOM</flag>
<border>5</border>
<object class="wxStaticText" name="m_label_Edad">
<label>Edad</label>
<wrap>-1</wrap>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALIGN_BOTTOM|wxALIGN_RIGHT|wxTOP|wxRIGHT|wxLEFT</flag>
<border>5</border>
<object class="wxSpinCtrl" name="m_spin_Edad">
<style>wxSP_ARROW_KEYS</style>
<value>0</value>
<min>0</min>
<max>10</max>
</object>
</object>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxEXPAND | wxALL</flag>
<border>5</border>
<object class="wxStaticLine" name="m_staticline1">
<style>wxLI_HORIZONTAL</style>
</object>
</object>
<object class="sizeritem">
<option>1</option>
<flag>wxEXPAND</flag>
<border>5</border>
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<option>1</option>
<flag>wxALL|wxEXPAND</flag>
<border>5</border>
<object class="wxRadioBox" name="m_radioBox_Sexo">
<label>Sexo</label>
<selection>0</selection>
<content>
<item>Hombre</item>
<item>Mujer</item>
</content>
<dimension>1</dimension>
</object>
</object>
<object class="sizeritem">
<option>1</option>
<flag>wxEXPAND|wxALL</flag>
<border>5</border>
<object class="wxStaticBoxSizer">
<orient>wxVERTICAL</orient>
<label>Preferencias</label>
<object class="sizeritem">
<option>0</option>
<flag>wxALL</flag>
<border>5</border>
<object class="wxCheckBox" name="m_checkBox_Cocacola">
<label>Cocacola</label>
<checked>0</checked>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALL</flag>
<border>5</border>
<object class="wxCheckBox" name="m_checkBox_FantaNaranja">
<label>Fanta naranja</label>
<checked>0</checked>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALL</flag>
<border>5</border>
<object class="wxCheckBox" name="m_checkBox_FantaLimon">
<label>Fanta Limon</label>
<checked>0</checked>
</object>
</object>
</object>
</object>
</object>
</object>
<object class="sizeritem">
<option>1</option>
<flag>wxEXPAND</flag>
<border>5</border>
<object class="wxStaticBoxSizer" name="Contenedor">
<orient>wxVERTICAL</orient>
<label>Contenedor</label>
<object class="sizeritem">
<option>0</option>
<flag>wxALL</flag>
<border>5</border>
<object class="wxButton" name="m_button4">
<label>MyButton</label>
<default>0</default>
</object>
</object>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALIGN_BOTTOM</flag>
<border>5</border>
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<option>0</option>
<flag>wxALL</flag>
<border>5</border>
<object class="wxButton" name="m_button_Guardar">
<label>Guardar</label>
<default>0</default>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALL</flag>
<border>5</border>
<object class="wxButton" name="m_button_Limpiar">
<label>Limpiar</label>
<default>0</default>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALL</flag>
<border>5</border>
<object class="wxButton" name="m_button_Salir">
<label>Salir</label>
<default>0</default>
</object>
</object>
</object>
</object>
</object>
</object>
</object>
</resource>
第二个(要作为数组重复的对象):
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1">
<object class="wxPanel" name="MyPanel6">
<style>wxTAB_TRAVERSAL</style>
<size>500,300</size>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="sizeritem">
<option>0</option>
<flag>wxALL</flag>
<border>5</border>
<object class="wxButton" name="m_button5">
<label>FRAME2</label>
<default>0</default>
</object>
</object>
</object>
</object>
</resource>
如何在主 XRC 内制作一系列 XRC 面板?谢谢