1 Attachment(s)
Checkable GroupBox problem
Dear experts,
In my application, I am using a custom control that is a GroupBox and a CheckBox instead of a common caption. I got the control here:
http://www.codeguru.com/cpp/cpp/cpp_...icle.php/c4149
I had to change the code to allow the checkbox to have multiline text:
Code:
CRect rc;
GetWindowRect(rc); // Get the rect of the GroupBox
this->ScreenToClient(rc);
// Change rc to be used for the checkbox
rc.left += 5;
rc.right = min(rc.left + czText.cx, rc.right - 5);
int iGroupBoxWidth = rc.right - rc.left;
double iLinesCount = ceil((double)czText.cx / iGroupBoxWidth);
rc.top -= (long)((iLinesCount - 1) * czText.cy / 2);
rc.bottom = (long)(rc.top + czText.cy * iLinesCount);
if(style == BS_AUTOCHECKBOX)
{
m_TitleBox.Create(strText, BS_AUTOCHECKBOX | BS_MULTILINE | WS_CHILD | WS_TABSTOP, rc, this, ID_TITLE);
}
As you can see, I change rc.top to have the middle of the checkbox neatly on the same level as the top edge of the groupbox, as in case of single-line caption. The multiline caption should be spread equally over and under that level. I can see that the checkbox is in the right place, so the top of the caption is calculated correctly, but the upper part of the caption text is cut off. I can see the caption not higher than the upper edge of the checkbox. Could you please tell me why this happens?
I have attached an image to show how it looks.
Thanks.
Re: Checkable GroupBox problem
Please:
- use Code tags
- attach an image (.jpg, .gif, ...) instead of .doc
Re: Checkable GroupBox problem
you're changing the top of where you are painting the text, but that just makes you write outside of the window rectangle. That isn't going to work properly since it's getting clipped.
Even if you "fix" the clipping in the DC before the paint may make it "sometimes" work, but repainting won't work properly if the area outside of your control gets invalidated for some reason. In that case the top will still be sliced off as it is now.
don't write outside of your window.
If you need more room "at the top", then you can't change just the top. Instead, you need to move everything inside the window downwards and adjust accordingly.
Re: Checkable GroupBox problem
Thank you very much for your answer. I am not sure I understand whether it would help to change the GroupBox window's rectangle. If yes, could you please give me an example how I could do it? I tried myself, but didn't succeed. And I am not concerned now with overlapping the GroupBox content.
1 Attachment(s)
Re: Checkable GroupBox problem
If you want "to have the middle of the checkbox neatly on the same level as the top edge of the groupbox" then add the style BS_TOP to your checkbox:
Re: Checkable GroupBox problem
Wow! It worked perfectly! Thank you very much!
Re: Checkable GroupBox problem
Quote:
Originally Posted by
dpreznik
Wow! It worked perfectly! Thank you very much!
No problem!
And you attached the image (rather than the .doc file that I couldn't open) in your OP you'd have got this solution yesterday! ;)