Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Static control positioned horizontally next to an Edit control. I want the text in both controls to align horizontally. The problem is I've noticed that when I run my program on different machines, they have different control padding. So the text will line up on one machine but not another. How can I correct for this?

If there is no way to do this, I guess I could change all my static controls to edit controls and override WM_NCHITTEST to essentially turn them into Static controls. Just thought there might be a way.
Posted
Updated 10-Mar-13 13:04pm
v2

1 solution

I think your assumption at and the idea at the end are correct.

I think the way if doing this alignment would be not quite reliable, because the shift between the control's client rectangle and the bounding rectangle of the text is the matter of internal design; it could be hard-coded in Microsoft source code, or something like that, and I know it's not the same for different controls. If somehow you take this shift into account now, nothing can guarantee it that you will have the same alignment of different version of the OS or for different UT themes selected by the user.

In addition to your own idea of hit test, you could use only text edit controls (aligned the way you wish), but some of them would be read-write and others read-only. You should not forget to use an appropriate color scheme so the user could clearly tell read-only edit control from others.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900