关于wxWigets中按钮与文本框的绑定,跪求各位大神帮忙

这是wxWidgets论坛的中文版本。在这里,您可以用您的母语汉语讨论上面任一子论坛所涉及的所有关于wxWidgets的话题。欢迎大家参与到对有价值的帖子的中英互译工作中来!
Post Reply
caserlee
In need of some credit
In need of some credit
Posts: 4
Joined: Wed Apr 20, 2016 1:45 pm

关于wxWigets中按钮与文本框的绑定,跪求各位大神帮忙

Post by caserlee » Wed Apr 20, 2016 1:52 pm

怎样将文本框和按钮绑定到一起,跪求帮助

Code: Select all

//创建一个基本的wxWidgets窗口
#include"wx/wx.h"
#include <wx/dialog.h>
#include<wx/textctrl.h>

class MyApp : public wxApp
{
public:
	//入口函数
	virtual bool OnInit();
};

//继承wxFrame
class MyFrame : public wxFrame
{
public:
	MyFrame(const wxString& label);
	//事件处理函数
	void OnQuit(wxCommandEvent& event);
	void OnAbout(wxCommandEvent& event);
	void OnSize(wxSizeEvent& event);
	void OnButtonOK(wxCommandEvent& event);
	void OnTEXTCtrl(wxCommandEvent& event);
	void funcName(wxCommandEvent& event);
	//增加一段空白
	void Add(int width, int height, int strech = 0, int flags = 0, int border = 0);
	//增加一段固定大小的空白
	void AddSpacer(int sizer);
	//增加一个可缩放的空白
	void AddStretchSpacer(int stretch = 1);
private:
	DECLARE_EVENT_TABLE()
};
//创建MyApp
DECLARE_APP(MyApp)
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
	//创建一个继承自wxFrame的窗口对象
	MyFrame * frame = new MyFrame(wxT("Minimal wxWidgets App"));

	frame->Show(true);
	return true;
}
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
EVT_SIZE(MyFrame::OnSize)
EVT_BUTTON(wxID_OK, MyFrame::OnButtonOK)
EVT_TEXT(wxID_ANY, MyFrame::OnTEXTCtrl)
END_EVENT_TABLE()
void MyFrame::OnAbout(wxCommandEvent& event)
{
	wxString msg;
	msg.Printf(wxT("Hello and welcome to %s"),
		wxVERSION_STRING);
	wxMessageBox(msg, wxT("About Minimal"),
		wxOK | wxICON_INFORMATION, this);
}
void MyFrame::OnQuit(wxCommandEvent& event)
{
	Close();
}
void MyFrame::OnSize(wxSizeEvent& event)
{

}
void MyFrame::OnButtonOK(wxCommandEvent& event)
{
	Close();

}
void MyFrame::OnTEXTCtrl(wxCommandEvent& event)
{
	wxLogMessage("Hello");
}

MyFrame::MyFrame(const wxString& label = wxEmptyString)
: wxFrame(NULL, wxID_ANY, label)

{
	//添加按钮控件

	

	wxBoxSizer*topSizer = new wxBoxSizer(wxVERTICAL);
	topSizer->Add(
//创建一个多行文本框
	    new wxTextCtrl(this, wxID_ANY, " hello",
		wxDefaultPosition,wxSize(150,90), wxTE_MULTILINE),
		1,
		wxEXPAND|
		wxALL,
		10);
	wxBoxSizer*buttonSizer = new wxBoxSizer(wxHORIZONTAL);
	buttonSizer->Add(
		new wxButton(this, wxID_OK, wxT("button")),
		0,
		wxALL,
		10);
	topSizer->Add(
		buttonSizer,
		0,
		wxALIGN_CENTER);
	SetSizer(topSizer);
	topSizer->Fit(this);
	topSizer->SetSizeHints(this);

	//SetIcon(wxIcon(mondrian xpm));
	//添加菜单控件
	wxMenu *fileMenu = new wxMenu;
	wxMenu *helpMenu = new wxMenu;
	helpMenu->Append(wxID_ABOUT, wxT("&About...\tF1"),
		wxT("Show about dialog"));
	fileMenu->Append(wxID_EXIT, wxT("E&xit\tAlt−X"),
		wxT("Quit this program"));
	wxMenuBar *menuBar = new wxMenuBar();
	menuBar->Append(fileMenu, wxT("&File"));
	menuBar->Append(helpMenu, wxT("&Help"));
	SetMenuBar(menuBar);
	CreateStatusBar(2);
	SetStatusText(wxT("Welcome to wxWidgets!"));
}
Last edited by catalin on Wed Apr 20, 2016 2:28 pm, edited 1 time in total.
Reason: Code tags, please use them

caserlee
In need of some credit
In need of some credit
Posts: 4
Joined: Wed Apr 20, 2016 1:45 pm

Re: 关于wxWigets中按钮与文本框的绑定,跪求各位大神帮忙

Post by caserlee » Wed Apr 20, 2016 2:01 pm

在vs软件下

caserlee
In need of some credit
In need of some credit
Posts: 4
Joined: Wed Apr 20, 2016 1:45 pm

Re: 关于wxWigets中按钮与文本框的绑定,跪求各位大神帮忙

Post by caserlee » Wed Apr 20, 2016 2:39 pm

能不能说的更清楚点,多谢

combo
In need of some credit
In need of some credit
Posts: 7
Joined: Sun Aug 26, 2012 10:09 pm

Re: 关于wxWigets中按钮与文本框的绑定,跪求各位大神帮忙

Post by combo » Tue Apr 26, 2016 8:24 am

没明白你的意思耶~
通常来说,同属一类的子控件是不需要绑定的啊,在对应的事件里面执行相应的代码,通过指针就可以实现通信或者直接操作了。
你的代码写得不好,通常是在frame里面放一个panel,然后各个子控件是放在panel里面的。

Post Reply