2013-04-08 54 views
0

我正在使用外部XRC方法實現與wxFormBuilder的用戶界面。在其他xrc內部署xrc

我想實現的是從wxStaticBoxSizer掛在這樣板陣列:在資源從「主」功能加載到它

wxXmlResource::Get()->Load("rc/resource2.xrc"); 

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); 
} 

。當啓動我的程序時,它可以工作,因爲我無法在任何地方看到這三個面板。

這是我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面板陣列? 謝謝

回答

1

首先,你的程序應該死亡可怕,因爲你從wxStaticBoxSizer鑄造到wxWindow。我真的不知道會給你什麼樣的印象,這是一個好主意。其次,在XRC中沒有重複對象的規定,並且一般來說,如果您需要類似的東西,在代碼中創建3個不同的面板會更容易和更好,從相同的資源中加載它們。但是,如果您真的想要,也可以使用object_ref XRC標記從其他位置引用現有對象。

+0

好吧,你是對的...從wxWindows投射到wxStaticBoxSizer類型不應該工作(但似乎工作??? aggg:S)。那麼如果我無法使用FindItem來做到這一點,我該如何獲取sizer指針呢? – 2013-04-08 15:33:19

+0

我會盡量按你說的去做。謝謝 – 2013-04-08 15:35:39

+0

你確定你需要sizer指針嗎?這很少有必要。如果您確實需要它,最簡單的方法是使用sizer獲取窗口並使用它的「GetSizer()」或包含在此sizer中的窗口並使用其「GetContainingSizer()」。 – 2013-04-08 15:58:16

相關問題