move control items in a dialogbox - Programmer

This is a discussion on move control items in a dialogbox - Programmer ; Hi, I am having a Dialogbox with two check boxes and 5 textboxes, Depending on a condition I want to hide 3 textboxes and remaining textboxes should be arranged (moved) to make the dialogbox compact.. also dialogbox needs to be ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: move control items in a dialogbox

  1. move control items in a dialogbox

    Hi,
    I am having a Dialogbox with two check boxes and 5 textboxes,
    Depending on a condition I want to hide 3 textboxes and remaining
    textboxes should be arranged (moved) to make the dialogbox compact..
    also dialogbox needs to be resized. Also all the controls moved and
    dialogbox resized .. i mean everything is reset when in another
    condition. How to go for it. How the control should be moved and
    dialogbox resized. How should be the flow of events. which classes to
    interact with.
    cric.


  2. Re: move control items in a dialogbox

    You might want to rethink your UI.

    Using "Dialog Units" will get you close, but with all the variations in
    fonts and screen resolutions, getting something that looks good everywhere
    could be a problem (for instance: how would you handle "dual monitor"
    screens?)

    --
    ---------------------------------------------------------------------
    DataGet & PocketLog www.dataget.com
    Data Collectors www.baxcode.com
    --------------------------------------------------------------------



    "cric" wrote in message
    news:1124179459.978233.283300@f14g2000cwb.googlegr oups.com...
    > Hi,
    > I am having a Dialogbox with two check boxes and 5 textboxes,
    > Depending on a condition I want to hide 3 textboxes and remaining
    > textboxes should be arranged (moved) to make the dialogbox compact..
    > also dialogbox needs to be resized. Also all the controls moved and
    > dialogbox resized .. i mean everything is reset when in another
    > condition. How to go for it. How the control should be moved and
    > dialogbox resized. How should be the flow of events. which classes to
    > interact with.
    > cric.
    >




  3. Re: move control items in a dialogbox

    Instead of hiding and moving controls look at just disabling the control you
    don't need. Moving controls may be confusing to some users.

    If disabling will not work, you can dynamically move the controls using the
    CDialog class and a couple functions (mainly GetWindowRect and SetWindowPos)
    From your description I'm assuming your dialog layout is 2 columns one with
    check boxes and one with the text boxes. Also let me assume that all your
    text boxes are the same size and space equally apart, this just makes
    explaining what needs to happen easier.

    Catch the WM_INITDIALOG message. In the message handler get the location of
    the 1st 2 text boxes. Store the height of the 1st text box and the
    difference between the 2 as a spacer as class variables.

    {
    CDialog::OnInitDialog();
    CRect recText2;
    GetDlgItem(IDC_EDIT1)->GetWindowRect(m_recText1);
    GetDlgItem(IDC_EDIT2)->GetWindowRect(recText2);
    m_iSpacer = recText2.top - m_recText1.bottom;
    ScreenToClient(m_recText1);
    }

    Create a function to call when you need to update the controls on the
    screen. The basic function works by tracking the next available position
    for a text box and tracking changes in the amount of space used for the text
    boxes. Once you have updated the text boxes the change in space used for
    the text boxes is added to the size of the dialog. Below is a simple
    example

    Resize function
    int iDelta = 0;
    int iTop = m_recText1.top;
    CRect recWindow;
    if (bShowEdit1)
    {
    if (!GetDlgItem(IDC_EDIT1)->IsWindowVisible())
    {
    iDelta += m_recText1.Height() + m_iSpacer;
    GetDlgItem(IDC_EDIT1)->ShowWindow(SW_SHOW);
    }
    iTop += m_recText1.Height() + m_iSpacer;
    }
    else if (GetDlgItem(IDC_EDIT1)->IsWindowVisible())
    {
    iDelta -= m_recText1.Height() + m_iSpacer;
    GetDlgItem(IDC_EDIT1)->ShowWindow(SW_HIDE);
    }
    if (bShowEdit2)
    {
    if (!GetDlgItem(IDC_EDIT2)->IsWindowVisible())
    {
    iDelta += m_recText1.Height() + m_iSpacer;
    }
    GetDlgItem(IDC_EDIT2)->GetWindowRect(recWindow);
    ScreenToClient(recWindow);
    GetDlgItem(IDC_EDIT2)->SetWindowPos(NULL,recWindow.left,iTop,
    0,0,SWP_NOZORDER | SWP_NOSIZE);
    GetDlgItem(IDC_EDIT2)->ShowWindow(SW_SHOW);
    iTop += m_recText1.Height() + m_iSpacer;
    }
    else if (GetDlgItem(IDC_EDIT2)->IsWindowVisible())
    {
    iDelta -= m_recText1.Height() + m_iSpacer;
    GetDlgItem(IDC_EDIT2)->ShowWindow(SW_HIDE);
    }
    /*
    * repeat the last if for all the other edit boxes
    */

    //TODO: Move any other controls below the text boxes (like the OK or cancel
    buttons)

    //adjust the dialog
    GetWindowRect(recWindow);
    SetWindowPos(NULL,0,0,recWindow.Width(), recWindow.Height() + iDelta,
    SWP_NOMOVE | SWP_NOZORDER);

    Depending on your dialog layout this may or may not work for what you are
    doing, but hopefully it will give you an idea of what is involved.

    -Eric

    "cric" wrote in message
    news:1124179459.978233.283300@f14g2000cwb.googlegr oups.com...
    > Hi,
    > I am having a Dialogbox with two check boxes and 5 textboxes,
    > Depending on a condition I want to hide 3 textboxes and remaining
    > textboxes should be arranged (moved) to make the dialogbox compact..
    > also dialogbox needs to be resized. Also all the controls moved and
    > dialogbox resized .. i mean everything is reset when in another
    > condition. How to go for it. How the control should be moved and
    > dialogbox resized. How should be the flow of events. which classes to
    > interact with.
    > cric.
    >




+ Reply to Thread