Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI, i have one group box inside that i haveseveral elements(some CEdit and CButton)
when i am resizing my window group box is resizing and i want to inside controls also should expand / shrink within the group boxes.
for resizing controls inside group box i have written below logic:


What I have tried:

RepositionControls(CRect& boundingRect)
{
    m_rGroupBox.MoveWindow(boundingRect, TRUE);
    CEdit* rEditPosRightToLeft[] = { &m_rPrefixEdit, &m_rpszFolderpath, &m_rMaxsizectl, &m_rLifetimectl };
    CButton* rButtonPosRightToLeft[] = { &m_rBtnSelect };
    for (size_t z = 0; z < (sizeof(rButtonPosRightToLeft) / sizeof(CButton*)); ++z) {
        CRect rectChildWindow;
        CButton& ctlButton(*rButtonPosRightToLeft[z]);
        ctlButton.GetWindowRect(&rectChildWindow);
        m_rLogStreamResizer.FetchTabDialog().ScreenToClient(&rectChildWindow);
        int nBtnWidth = rectChildWindow.Width();
        int nBtnHeight = rectChildWindow.Height();
        int bx = m_nSideButtonX;
        int by = rectChildWindow.top;
        ctlButton.MoveWindow(bx, by, nBtnWidth, nBtnHeight, TRUE);       
    }
    /*  TODO: need to implement for the  edit controls*/
    for (size_t z = 0; z < (sizeof(rEditPosRightToLeft) / sizeof(CEdit*)); ++z) {
        CRect rectChildWindow;
        CEdit& ctlButton(*rEditPosRightToLeft[z]);
        ctlButton.GetWindowRect(&rectChildWindow);
        m_rLogStreamResizer.FetchTabDialog().ScreenToClient(&rectChildWindow);
        int nBtnWidth = rectChildWindow.Width();
        int nBtnHeight = rectChildWindow.Height();
        int bx = m_nSideButtonX;
        int by = rectChildWindow.top;
        ctlButton.MoveWindow(bx, by, nBtnWidth, nBtnHeight, TRUE);
    }


in above code for CButton logic its working fine but for CEdit controls not working inCEdit control i have chage the width of the edit control depends on resizing
could you please help me here
Posted
Updated 24-Jul-17 20:58pm

1 solution

You have to calculate the width according to the available width, the number of controls, and the spacing between the controls and to the borders.

Assuming you have a left and right space to the borders and a space between the controls the width of a single control can be calculated as:
C++
int availWidth = boundingRect.Width();
int numControls = sizeof(rEditPosRightToLeft) / sizeof(rEditPosRightToLeft[0]);
const int borderSpace = 2; // or whatever you want
const int betweenSpace = 4;
int controlWidth = (availWidth - 2 * borderSpace - (numControls - 1) * betweenSpace) / numControls;
You have also to calculate the left position for each control. It starts at borderSpace and must be incremented by controlWidth + betweenSpace with each loop iteration. If the above controlWidth calculation has a remainder from the final division, you might also get that and use it up while calculating the x positions.
 
Share this answer
 
Comments
Member 13089825 27-Jul-17 2:31am    
HI thank you for your reply.
Could you please give me some more guidance.
here i want resize the controls both left right(only width need to be updated as per resizing ) and top to bottom(y position need to be changed for top to bottom)
Jochen Arndt 27-Jul-17 2:57am    
It is done similar.
I suggest to use a piece of paper to visualise the required positions, sizes, and distances (spaces between elements). This makes its much simpler to get the required calculation formulas.
Member 13089825 27-Jul-17 8:52am    
thank you very much.
Its working fine now.
Jochen Arndt 27-Jul-17 8:54am    
Fine to hear that it is working now.

Thank you for the feedback and accepting my solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900