【发布时间】:2021-03-31 04:53:12
【问题描述】:
我使用“wxPopupTransientWindow”创建了一个弹出窗口并添加了一些文本和一个按钮。现在我只想在单击此特定按钮时销毁此弹出窗口。现在,如果点击它之外的任何地方,Popup 将被破坏。 这是我到目前为止所尝试的。
SimpleTransientPopup::SimpleTransientPopup(wxWindow *parent, bool scrolled) : wxPopupTransientWindow(parent, wxFRAME_SHAPED)
{
m_bGotItClick = false;
m_panel = new wxScrolledWindow(this,-1,wxDefaultPosition,wxDefaultSize);
m_panel->SetBackgroundColour(*wxYELLOW);
wxStaticText *text = new wxStaticText( m_panel, wxID_ANY,
"This panel will guide you stepwise through the workflow\n");
wxPanel *pBottomPanel = new wxPanel(m_panel, -1);
m_button = new wxButton(pBottomPanel, Minimal_PopupButton, "Got it!",wxDefaultPosition, wxDefaultSize);
m_link = new wxHyperlinkCtrl(pBottomPanel, Minimal_PopupLink, _("Hide these tips"), _(""), wxDefaultPosition, wxDefaultSize, wxHL_ALIGN_LEFT);
m_link->SetFont(wxFont(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_ITALIC, wxFONTWEIGHT_NORMAL, true));
m_link->SetNormalColour(*wxLIGHT_GREY);
m_link->SetForegroundColour(*wxLIGHT_GREY);
wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
wxBoxSizer *bottomSizer = new wxBoxSizer(wxHORIZONTAL);
bottomSizer->Add(m_link,0,wxALL,20);
bottomSizer->AddStretchSpacer();
bottomSizer->Add(m_button, 0, wxALL, 20);
pBottomPanel->SetAutoLayout(true);
pBottomPanel->SetSizer(bottomSizer);
bottomSizer->SetSizeHints(pBottomPanel);
bottomSizer->Fit(pBottomPanel);
topSizer->Add(text, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 20);
topSizer->Add(pBottomPanel,0,wxEXPAND);
m_panel->SetSizer( topSizer );
// Use the fitting size for the panel if we don't need scrollbars.
topSizer->Fit(m_panel);
SetClientSize(m_panel->GetSize());
wxTipKind tipKind = wxTipKind_Auto;
const int offsetY = SetTipShapeAndSize(tipKind, GetBestSize());
if (offsetY > 0)
{
// Offset our contents by the tip height to make it appear in the
// main rectangle.
topSizer->PrependSpacer(offsetY);
}
m_panel->Fit();
}
我在单击按钮时调用此 OnDismiss 函数。
void SimpleTransientPopup::OnDismiss()
{
if (m_bGotItClick) {
wxLogMessage("%p SimpleTransientPopup::OnDismiss", this);
wxPopupTransientWindow::OnDismiss();
m_bGotItClick = false;
}
}
PS:我是 wxWidgets 的新手
【问题讨论】:
标签: c++ visual-studio wxwidgets visual-studio-debugging pdb-files