Results 1 to 2 of 2

Thread: Margins within a cell

  1. #1
    Junior Member
    Join Date
    Dec 2011

    Margins within a cell

    As another way of approaching the problem in another question about number format in cells, I have tried to set the right margin so it aligns with the right margin of the combo box under. If I then right align things in both cells, they should be neatly aligned even though one has an arrow at the right, since it's a combo box.

    But if I try:

    SetStyleRange(nRow, nCol, nRow, nCol,
    CGXStyle().SetHorizontalAlignment(DT_RIGHT).SetCon trol(GX_IDS_CTRL_EDIT));
    CGXEditControl* thisEditControl = (CGXEditControl*)GetControl(nRow, nCol);
    if (thisEditControl)
    DWORD margins = thisEditControl->GetMargins();
    UINT nLeft = LOWORD(margins);
    UINT nRight = HIWORD(margins);
    thisEditControl->SetMargins(nLeft, 40);
    margins = thisEditControl->GetMargins();
    nLeft = LOWORD(margins);
    nRight = HIWORD(margins);

    the margins don't get changed! When calling GetMargins right after SetMargins(nLeft, 40), the right margin is still returned as 0. Why?

    Then I tried subclassing CGXEditControl. But I can't find out what function to override to tell: "When you think you now where to put the text in this cell, put it X pixels to the left instead". Also, I don't know how to calculate exactly how many pixels this should be, since it depends on the difference in "right text position" in a CGXEditControl vs the same in a CGXComboBox with a visible arrow.

    Any tips appreciated!

  2. #2
    Junior Member
    Join Date
    Dec 2011
    I found the solution myself. First a created a global value m_rightMargin (should be put somewhere else I'm sure, but it works) to store the amount I need to pad in the edit control. To find this, I subclass the combo box and override:

    CRect MyComboBoxControl::GetCellRect(ROWCOL nRow, ROWCOL nCol, LPRECT rectItem /* = NULL */, const CGXStyle* pStyle /* = NULL */)
    CRect editCtrlRect = CGXEditControl::GetCellRect(nRow, nCol, rectItem, pStyle);
    CRect comboBoxRect = CGXComboBox::GetCellRect(nRow, nCol, rectItem, pStyle);
    m_rightMargin = editCtrlRect.Width() - comboBoxRect.Width();
    return comboBoxRect;

    Then in the same function in the edit control:

    CRect MyEditControl::GetCellRect(ROWCOL nRow, ROWCOL nCol, LPRECT rectItem /* = NULL */, const CGXStyle* pStyle /* = NULL */)
    CRect returnRect = CGXEditControl::GetCellRect(nRow, nCol, rectItem, pStyle);
    returnRect.right -= m_rightMargin;
    return returnRect;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts