Search code examples
wxwidgets

What is the wxWidgets equivalent of a C# User Control


I am currently designing the migration of my existing .NET / C# / WinForms project to a platform neutral solution and the most attractive alternative I have seen seems to be wxWidgets especially taking in consideration my familiarity with C++ and with MFC that appears to have a lot in common with it.

After going though the documentation and the sample code I need to clarify the following issue:

Is it a valid assumption that the way to develop a User Control (by C# terminology) in a wx environment is to derive a class from wxPanel , customize it and place it in a wxFrame? If this is the case what is the wxFrame method to be used to add the wxPanel object to it ?

The only relative method I was able to find was wxWindow::AddChild but the documentation states that is mostly internal to wxWidgets and shouldn't be called by the user code.

To avoid confusion please note that my question is about a User Control and not a Custom Control (which is clearly addressed in the documentation)


Solution

  • I think you have to set the parent window in the constructor of your wxPanel-derived class and pass it to the inherited constructor (cf. wxPanel constructor)

    A better solution, though, is to use sizers (see wx Sizers) for layouting.

    And yes, imo you're right about wxPanelbeing (roughly) the equivalent of a C# UserControl.