Code: Select all
#include<wx/wx.h>
#include<wx/popupwin.h>
#include<wx/statline.h>
class MyFrame : public wxFrame{
wxPanel *panel,*p;
wxBoxSizer *vbox,*hbox;
wxStaticText *st;
wxButton *btn;
wxTextCtrl *txt1;
int i=0;
public :
MyFrame():wxFrame(NULL,wxID_ANY,"Child Focus"){
SetSize(800,550);
wxPopupWindow *pop=new wxPopupWindow(this);
pop->SetSize(650,250);
vbox=new wxBoxSizer(wxVERTICAL);
hbox=new wxBoxSizer(wxHORIZONTAL);
p=new wxPanel(pop,wxID_ANY,wxDefaultPosition,wxSize(-1,30));
p->SetFont(wxFont(14,wxFONTFAMILY_DEFAULT,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_BOLD,false,"Georgia"));
p->SetForegroundColour(wxColour("#000000"));
p->SetBackgroundColour(wxColour("#FBC403"));
hbox->Add(new wxStaticText(p,wxID_ANY,wxT("Product Information : ")),0,wxEXPAND|wxLEFT|wxTOP,5);
p->SetSizer(hbox);
vbox->Add(p,0,wxEXPAND);
vbox->AddSpacer(5);
hbox=new wxBoxSizer(wxHORIZONTAL);
st=new wxStaticText(pop,wxID_ANY,wxT("Product Name : "),wxDefaultPosition,wxSize(132,30));
hbox->Add(st);
txt1=new wxTextCtrl(pop,wxID_ANY,wxT("1234567890"),wxDefaultPosition,wxSize(200,30));
txt1->SetBackgroundColour(wxColour("#000000"));
txt1->SetForegroundColour(wxColour("#FBC403"));
hbox->Add(txt1);
hbox->AddStretchSpacer();
st=new wxStaticText(pop,wxID_ANY,wxT("Pack : "));
hbox->Add(st);
txt1=new wxTextCtrl(pop,wxID_ANY,wxT("10"),wxDefaultPosition,wxSize(200,30));
txt1->SetBackgroundColour(wxColour("#000000"));
txt1->SetForegroundColour(wxColour("#FBC403"));
txt1->SetFocus();
hbox->Add(txt1);
vbox->Add(hbox,0,wxEXPAND|wxALL,5);
vbox->AddSpacer(5);
hbox=new wxBoxSizer(wxHORIZONTAL);
st=new wxStaticText(pop,wxID_ANY,wxT("Company : "),wxDefaultPosition,wxSize(132,30));
hbox->Add(st);
txt1=new wxTextCtrl(pop,wxID_ANY,wxT("ABC Company"),wxDefaultPosition,wxSize(200,30));
txt1->SetBackgroundColour(wxColour("#000000"));
txt1->SetForegroundColour(wxColour("#FBC403"));
hbox->Add(txt1);
hbox->AddStretchSpacer();
st=new wxStaticText(pop,wxID_ANY,wxT("Category : "));
hbox->Add(st);
txt1=new wxTextCtrl(pop,wxID_ANY,wxT("General"),wxDefaultPosition,wxSize(200,30));
txt1->SetBackgroundColour(wxColour("#000000"));
txt1->SetForegroundColour(wxColour("#FBC403"));
hbox->Add(txt1);
vbox->Add(hbox,0,wxEXPAND|wxALL,5);
vbox->AddSpacer(5);
hbox=new wxBoxSizer(wxHORIZONTAL);
st=new wxStaticText(pop,wxID_ANY,wxT("GST : "),wxDefaultPosition,wxSize(132,30));
hbox->Add(st);
txt1=new wxTextCtrl(pop,wxID_ANY,wxT("18%"),wxDefaultPosition,wxSize(200,30));
txt1->SetBackgroundColour(wxColour("#000000"));
txt1->SetForegroundColour(wxColour("#FBC403"));
hbox->Add(txt1);
hbox->AddStretchSpacer();
st=new wxStaticText(pop,wxID_ANY,wxT("Hazardous : "));
hbox->Add(st);
txt1=new wxTextCtrl(pop,wxID_ANY,wxT("No"),wxDefaultPosition,wxSize(200,30));
txt1->SetBackgroundColour(wxColour("#000000"));
txt1->SetForegroundColour(wxColour("#FBC403"));
hbox->Add(txt1);
vbox->Add(hbox,0,wxEXPAND|wxALL,5);
vbox->AddSpacer(5);
vbox->Add(new wxStaticLine(pop),0,wxEXPAND);
pop->SetSizer(vbox);
pop->Center();
pop->Show(true);
pop->Layout();
this->Layout();
pop->SetFocus();
txt1->SetFocus();
}
};
class MyApp: public wxApp
{
wxFrame* m_frame;
public:
bool OnInit()
{
m_frame = new MyFrame();
m_frame->Show();
return true;
}
};
IMPLEMENT_APP(MyApp);
Any of the wxTextCtrl do not get focus even after mouse click.
Is There any solution to set focus on creation of wxPopupWindow ?