CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2009
    Posts
    27

    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.
    Attached Images Attached Images
    Last edited by dpreznik; February 9th, 2011 at 04:22 PM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Checkable GroupBox problem

    Please:
    1. use Code tags
    2. attach an image (.jpg, .gif, ...) instead of .doc
    Victor Nijegorodov

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    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.

  4. #4
    Join Date
    Aug 2009
    Posts
    27

    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.

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    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:
    Attached Images Attached Images
    Victor Nijegorodov

  6. #6
    Join Date
    Aug 2009
    Posts
    27

    Re: Checkable GroupBox problem

    Wow! It worked perfectly! Thank you very much!

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Checkable GroupBox problem

    Quote Originally Posted by dpreznik View Post
    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!
    Victor Nijegorodov

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured