Creating a Dialog

team bbl


Create a new dialog either using the drop-down menu on the New Top-Level Element toolbar button or from the Element menu. Fill in the title, class name, and C++ file names for this dialog. A dialog starts out with a default vertical box sizer, but you can delete this and replace it with a different sizer.

Select the top-level sizer and add a wxButton by clicking on the left-most button in the dialog editor toolbar (just above the property editor). Now add a single-line wxTextCtrl. It appears beneath the button because the containing sizer is a vertical box sizer. Now try adding a horizontal box sizer, then several buttons. The horizontal box sizer will stretch to fit the new buttons, expanding the dialog (Figure C-5).

Figure C-5. A simple dialog with two sizers


The first button you created is now centered in the horizontal axis because this is the default. You can experiment with different alignments using the yellow toolbar buttons.

Now select the wxTextCtrl you created earlier and add a wxListBox. It's created just after the text control with a default size; you can make it stretch to fit the available horizontal space by clicking on the Expand Horizontally button. Try previewing the dialog with F5 and resizing it. You'll notice that there's a lot of empty space if you make the dialog big (Figure C-6).

Figure C-6. Wasted space when resizing


Close the preview, click on the list box, and click on the double-headed arrow ("the stretch factor"). Now resizing the dialog makes the list box grow to take up available space (Figure C-7).

Figure C-7. Stretching a control to fit available space


By default, DialogBlocks creates a dialog with the Fit to Content property on so that the dialog will wrap around the content. If you want the dialog to show at a predetermined size initially and have the content stretch appropriately, switch this property off and provide suitable Width and Height property values for the dialog.

    team bbl



    Cross-Platform GUI Programming with wxWidgets
    Cross-Platform GUI Programming with wxWidgets
    ISBN: 0131473816
    EAN: 2147483647
    Year: 2005
    Pages: 262

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net