I need some guidance on understanding how SetTextMargin works for CButton. What I am trying to do is have a CButton which has BS_LEFT style and using SetIcon setting an icon on the button which will appear on the left. Now the text needs to be set with some margin so that it doesn't stick too close to the icon. I have some calculations on what the margin should be. Now the CButton::SetTextMargin takes in a CRect parameter and I need help understanding what my rect.right and rect.left should be. I have tried all sorts of tests but I am not able to get how the margin rectangle gets incorporated. My calculations of the margin and the actual margin is way off. Any help would be appreciated. Thanks!
Asked
Active
Viewed 358 times
1
-
Is it not possible to use the CMFCButton class as it supports showing text and images already? – Andrew Truckle Apr 14 '16 at 02:58
-
I tried it out but I wasn't able to get the buttons match the native UI theme on different Windows OSes. Not sure how the CRect really fits in but I figured that whatever width was being set for the CRect in the code (rect.right - rect.left), on screen, the space between the image and text was half of that. So I got it working for now but I would still like to understand where CRect would really fit in the button. – overflowingstack Apr 14 '16 at 22:41
1 Answers
0
Just answering this part of the question:
Now the CButton::SetTextMargin takes in a CRect parameter and I need help understanding what my rect.right and rect.left should be.
The CRect represents how large you want the margins to be. Setting rect.right = 0
will give you no margin on the right.

serg06
- 2,027
- 1
- 18
- 26