How to call an event handler method directly in wx

2019-09-05 07:24发布

Visual Studio 2008 C++ Windows Xp SP3

I have created a wxWidgets form (using wxFormBuilder) and have buttons/menus/toolbars all generating events to call various methods (all this works perfectly). Each of these event methods is defined like this:

void cLoggingFrame::me_InsertCommentText(wxCommandEvent& event);

Now, what I want to be able to do is 're-use' some of these methods by calling them directly. I don't want to generate an event to be handled, I want the method to run when I call it. For example, I want to do something like this (this doesn't work)

me_InsertCommentText(NULL);

Now, I understand that I could have each event method just call another method (without parameters) that could be called from other locations, but in other languages I've been able to bypass the parameter requirement with NULL.

Is there any way to do this with wxWidgets without the need for an additional method?

2条回答
劫难
2楼-- · 2019-09-05 07:49

Methods passed to Event-Handlers are just ordinary c++ methods, you have to pass correct parametes something like this will do the trick

me_InsertCommentText(wxCommandEvent());
查看更多
来,给爷笑一个
3楼-- · 2019-09-05 07:53

just use the event variable that is already created by wxwidgets. The command line should be like this:

me_InsertCommentText(event);

查看更多
登录 后发表回答