将静态控件中的文本与“编辑”或“Rich Edit”控件中的文本对齐 [英] Align text in a Static control with text in an Edit or Rich Edit control

查看:95
本文介绍了将静态控件中的文本与“编辑”或“Rich Edit”控件中的文本对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个静态控件水平放置在编辑控件旁边。我希望两个控件中的文本水平对齐。问题是我注意到当我在不同的机器上运行我的程序时,它们有不同的控件填充。因此,文本将排在一台机器上而不是另一台机器上。我怎么能纠正这个?



如果没有办法做到这一点,我想我可以改变所有静态控件来编辑控件并覆盖WM_NCHITTEST基本上转向他们进入静态控件。只是觉得可能有办法。

解决方案

我认为你的假设和最后的想法是正确的。



我认为如果做这种对齐的方式不太可靠,因为控件的客户端矩形和文本的边界矩形之间的转换是内部设计的问题;它可以在Microsoft源代码中硬编码,或类似的东西,我知道它对于不同的控件是不一样的。如果你现在以某种方式考虑这个转变,没有什么可以保证你将拥有相同的操作系统版本或用户选择的不同UT主题的对齐方式。



除了你自己的命中测试的想法,你可以只使用文本编辑控件(按照你希望的方式对齐),但其中一些是读写,其他是只读。您不应忘记使用适当的配色方案,以便用户可以清楚地告诉其他人只读编辑控件。



-SA

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.

解决方案

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


这篇关于将静态控件中的文本与“编辑”或“Rich Edit”控件中的文本对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆