make a wxDialog resizable Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

make a wxDialog resizable

Post by MoonKid »

How can I set a wxDialog to be resizable with the mouse cursor?

There is wxRESIZE_BORDER, but it is just the affect that a resize cursor apears over the border. But I can not touch and resize the border.

Could it something be with my layout/sizers?
That is the Init-Methode of my wxDialog derived class:

Code: Select all

    // the files
    wxArrayString arrLogs(BFRootTask::Instance().GetLastLogFiles());

    // the book
    wxNotebook* pBook = new wxNotebook (this, wxID_ANY);
    pBook->SetMinSize(wxSize(500, 400));
    wxSizer* pBookSizer = new wxBoxSizer(wxVERTICAL);
    pBookSizer->Add(pBook);

    // the log files
    for (int i = 0; i < arrLogs.GetCount(); ++i)
    {
        // the log file
        wxTextFile fileLog;
        fileLog.Open(arrLogs[i]);

        // error while opening
        if ( !(fileLog.IsOpened()) )
        {
            BFSystem::Error(wxString::Format(_("can not open the log file %s"), arrLogs[i].c_str()), _T("BFLogViewDlg::Init()"));
            continue;
        }

        // create the text control
        wxTextCtrl* pCtrl = new wxTextCtrl(pBook,
                                           wxID_ANY,
                                           wxEmptyString,
                                           wxDefaultPosition,
                                           wxDefaultSize,
                                           wxTE_MULTILINE | wxTE_READONLY);
        wxFont font(pCtrl->GetFont());
        font.SetFaceName(_T("Courier New"));
        font.SetFamily(wxFONTFAMILY_MODERN);
        font.SetPointSize(8);
        pCtrl->SetFont(font);

        // read the file
        for (wxString strLine = fileLog.GetFirstLine();
             !fileLog.Eof();
             strLine = fileLog.GetNextLine())
        {
            (*pCtrl) << strLine << _T("\n");
        }



        // add as a tab
        pBook->AddPage(pCtrl, arrLogs[i]);
    }

    SetSizerAndFit(pBookSizer);
lvdlinden
Earned some good credits
Earned some good credits
Posts: 147
Joined: Thu May 17, 2007 7:03 am
Location: 's-Hertogenbosch, Netherlands

Post by lvdlinden »

Adding wxRESIZE_BORDER should make a wxDialog resizable. Perhaps you should try an empty dialog first and see if it works then.
ebyrob
Knows some wx things
Knows some wx things
Posts: 27
Joined: Wed Sep 28, 2016 8:27 pm

Re: make a wxDialog resizable

Post by ebyrob »

I'm having the same problem as the OP on Win7 64-bit Visual Studio 2010 version 3.1.0 of wx. I've got a wxDialog and I'd like to make it re-sizeable, but it won't resize. (wxFrame works fine btw)

Here is a full program in one C++ file with the problem:

Code: Select all

#define WIN32_LEAN_AND_MEAN
#define _CRT_SECURE_NO_WARNINGS
#define WXUSINGDLL
#include <windows.h> // running on Windows 7 64-bit built with Visual Studio 2010
#include <wx/wx.h>   // #define wxVERSION_STRING   wxT("wxWidgets 3.1.0")    from <wx/version.h>

class MyApp : public wxApp
{
public:
    virtual bool OnInit();
};

#define MyBaseWindow wxDialog
class MyDialog : public MyBaseWindow // derive from either wxDialog or wxFrame using #define above.
{
public:
    MyDialog();
private:
    void OnClose(wxCloseEvent& evt) { Destroy(); evt.Skip(); }
};

wxIMPLEMENT_APP(MyApp);

bool MyApp::OnInit()
{
    MyDialog *pdlg = new MyDialog();
    pdlg->Show(true); // pdlg->ShowModal(); // either should work.
    return true;
}

MyDialog::MyDialog() : MyBaseWindow(NULL, wxID_ANY, "resize test")
{
    Connect(wxID_ANY, wxEVT_CLOSE_WINDOW, wxCloseEventHandler(MyDialog::OnClose)); // EVT_CLOSE(CERPFrame::OnClose)
    wxStaticText *text = new wxStaticText(this, wxID_ANY, "set wxRESIZE_BORDER but can't resize");
    this->SetWindowStyle(this->GetWindowStyle() | wxRESIZE_BORDER);       // enables resize border, but resize doesn't work for wxDialog.
    // this->SetWindowStyle(this->GetWindowStyle() & (~wxRESIZE_BORDER)); // disables resize border and can't resize.
}
If you run it, you can see the mouse-over resize icons, but the dialog won't actually resize.
Operating System: Windows 1-, 64-bit / macOS 13.4.1, Apple M1
Compiler: Visual Studio 2019 / Xcode 14.3.1
wxWidgets version: 3.1.0 / 3.2.2
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: make a wxDialog resizable

Post by doublemax »

Not all window style flags can be changed after a window was created. You need to pass the proper style flag to the constructor.

Code: Select all

MyDialog::MyDialog() : MyBaseWindow(NULL, wxID_ANY, "resize test", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER )
{
    Connect(wxID_ANY, wxEVT_CLOSE_WINDOW, wxCloseEventHandler(MyDialog::OnClose)); // EVT_CLOSE(CERPFrame::OnClose)
    wxStaticText *text = new wxStaticText(this, wxID_ANY, "set wxRESIZE_BORDER but can't resize");
}
Use the source, Luke!
ebyrob
Knows some wx things
Knows some wx things
Posts: 27
Joined: Wed Sep 28, 2016 8:27 pm

Re: make a wxDialog resizable

Post by ebyrob »

Thanks! Setting the style in the call to wxDialog() constructor did the trick!
Operating System: Windows 1-, 64-bit / macOS 13.4.1, Apple M1
Compiler: Visual Studio 2019 / Xcode 14.3.1
wxWidgets version: 3.1.0 / 3.2.2
Post Reply