VC 动态创建Checkbox 位置 问题?
本帖最后由 VisualEleven 于 2012-12-05 15:41:16 编辑 如题, 现在我有多个Checkbox,需分两排显示。
for (int i = 1; i < ChkCount; i++)
{
CButton* MyChk;
MyChk = new CButton();
CWnd *pWnd = new CWnd;
pWnd = GetDlgItem(IDC_InstallGp);
if (i % 2 != 0)
{
MyChk->Create("22222", WS_TABSTOP|WS_VISIBLE|WS_CHILD|BS_AUTOCHECKBOX, CRect(10,i * 20,100,i * 30), pWnd, i);
}
else
{
MyChk->Create("22222", WS_TABSTOP|WS_VISIBLE|WS_CHILD|BS_AUTOCHECKBOX, CRect(340,(i - 1) * 20,1200,(i + 1) * 30), pWnd, i);
}
}
#define MAX_COUNT(33) // CheckBox的总个数
#define MAX_ROW(2) // 一排最大放2个CheckBox
#define IDC_CHECKBOX(0x11) // 控件的ID号
CButton* pButton = NULL;
CString strText(_T(""));
CONST UINT MAX_CHECKBOX_WIDTH = 120; // 定义CheckBox的宽度
CONST UINT MAX_CHECKBOX_HEIGHT = 20; // 定义CheckBox的高度
CONST UINT MAX_CHECKBOX_X_GAP = 20; // 定义CheckBox之间的水平间隔距离
CONST UINT MAX_CHECKBOX_Y_GAP = 20; // 定义CheckBox之间的垂直间隔距离
CRect rect;
rect.SetRectEmpty();
for(int i = 0; i != MAX_COUNT; ++i)
{
if(0 == (i % 2))
{
rect.left = 10;
rect.top = rect.bottom + MAX_CHECKBOX_Y_GAP;
}
else
{
rect.left = rect.right + MAX_CHECKBOX_X_GAP;
}
rect.right = rect.left + MAX_CHECKBOX_WIDTH;
rect.bottom = rect.top + MAX_CHECKBOX_HEIGHT;
strText.Format(_T("CheckBox - %d"), i+1);
pButton = new CButton;
ASSERT(NULL != pButton);
VERIFY(pButton->Create(strText, WS_TABSTOP
[其他解释]
WS_VISIBLE