调整组框内的项目大小 [英] Resizing items inside group box

查看:66
本文介绍了调整组框内的项目大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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);
    }





以上代码中的CButton逻辑工作正常但CEdit控件无法工作在ECC控件中我有宽度编辑控件取决于调整大小

你能帮我吗



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

推荐答案

你必须根据可用的宽度来计算宽度,控件的数量,以及控件和边框之间的间距。



假设边框有左右空间,控件之间有空格单个控件的宽度可以计算为:

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:
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;

您还必须计算每个控件的左侧位置。它从 borderSpace 开始,并且每次循环迭代必须以 controlWidth + betweenSpace 递增。如果上面的 controlWidth 计算得到最终除法的余数,你也可以得到它并在计算 x 职位。

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.


这篇关于调整组框内的项目大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆