【问题标题】:How do I get back to the parent frame in wxWidgets C++?如何返回 wxWidgets C++ 中的父框架?
【发布时间】:2021-08-05 14:12:19
【问题描述】:

我已经创建了这个登录表单。它的工作原理是这样的:cMain 是您放置登录凭据的主要登录类,user_reg 是用户创建类。我想从 cMain 框架到 user_reg 框架并返回。到目前为止,我只是通过不关闭 cMain 框架来解决这个问题,但对我来说这不是解决方案。有什么办法可以让我去 cMain -> user_reg -> cMain 吗? 这是我尝试过的

//cMain.h
#pragma once
#include "wx/wx.h"
#include "wx/msgdlg.h"
#include "wx/font.h"
#include "user_reg.h"
#include "account.h"
#include "gui.h"
#include <fstream>

class cMain : public wxFrame
{
public:
    cMain();
    ~cMain();

private:
    gui* m_frame2 = nullptr;
    user_reg* m_frame3 = nullptr; //Works fine
public:
    //Ignore this
    wxButton* m_btn1 = nullptr;
    wxStaticText* m_text1 = nullptr;
    wxStaticText* m_text2 = nullptr;
    wxButton* m_btn2 = nullptr;
    wxTextCtrl* m_txt1 = nullptr;
    wxTextCtrl* m_txt2 = nullptr;
    wxListBox* m_list1 = nullptr;
    wxMessageDialog* m_msg1 = nullptr;
    void OnLogin(wxCommandEvent& evt);
    void OnRegister(wxCommandEvent& evt);

    wxDECLARE_EVENT_TABLE();
};

//user_reg.h
#pragma once
#include <string>
#include "wx/wx.h"
#include "wx/msgdlg.h"
#include "account.h"
#include "encrypt.h"
#include "cMain.h"

class user_reg : public wxFrame
{
public:
    user_reg();
    ~user_reg();
private:
    cMain* m_frame1 = nullptr; //Does not work, error here
public:
    //Ignore this
    wxTextCtrl* m_txt1 = nullptr;
    wxTextCtrl* m_txt2 = nullptr;
    wxTextCtrl* m_txt3 = nullptr;
    wxButton* m_btn1 = nullptr;
    wxMessageDialog* m_msg1 = nullptr;

    void onRegister(wxCommandEvent& evt);
    wxDECLARE_EVENT_TABLE();
};
//cMain.cpp

...
m_frame3 = new user_reg(); //Works fine
    m_frame3->Show(); //Works fine
    Close(); //This should not be here, this represents the ideal use case
    evt.Skip();
...

//user_reg.cpp
...
    m_frame1 = new cMain(); //Does not work
    m_frame1->Show(); //Does not work
    Close();
    evt.Skip();
...

非常感谢任何帮助或文档,在此先感谢。

【问题讨论】:

    标签: c++ wxwidgets


    【解决方案1】:

    做你想做的最简单的方法是使用一个模态对话框,即一个wxDialog派生类,你在其上调用ShowModal(),用于你的用户注册表。

    从 UI 的角度来看,更好的解决方案可能是将用户注册控件放在主框架本身内,并根据需要显示/隐藏它们。例如。您可以使用wxSimplebook 并将注册表单设置为另一个页面。

    当然,也可以显示另一个框架,就像您现在正在尝试做的那样。在这种情况下,您可能希望在显示第二帧时禁用第一帧,然后重新启用它。这是ShowModal() 自动为您做的事情。

    【讨论】:

    • 好的,所以 wxDialog 将充当框架,但我仍然可以将 wxButton、wxTextCtrl 之类的东西放入其中吗?感谢您的提醒
    • @Denis9365,当然。是什么阻止你这样做?
    猜你喜欢
    • 1970-01-01
    • 2010-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-30
    • 1970-01-01
    相关资源
    最近更新 更多