CComboBoxEx 不同 DPI、高度计算的问题
我想在窗体上添加 CComboBoxEx,但我必须将其与其他控件对齐并使其高度相同。
问题是我找不到获取此控件高度的正确方法。
如果我设置窗口矩形,则会影响下拉列表框。如果我强制它为某个固定大小,并且组合内的内容较高,则控件会被剪裁在底部。
有没有办法根据图像和当前 DPI 设置计算 ComboBoxEx 有多大?这样,如果我无法调整控件的内部填充,我至少可以扩展其他控件。据我所知,MSDN 根本没有涉及大小问题。
I want to add a CComboBoxEx on my form, but I have to align it with other controls and make it the same height.
The problem is that I can't find which is the correct way to get the height of this control.
If I set the window rectangle, that affects the drop down listbox. If I force it to be some fixed size, and the content inside the combo is higher, the control gets clipped at the bottom.
Is there a way to calculate how big the ComboBoxEx will be, based on image and current DPI settings? So that I could at least expand the other controls if I cannot adjust the internal padding of the control. MSDN doesn't touch the sizing issues at all as far as I've looked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
组合框自动设置控件的高度,正如您所发现的,尝试设置自己的高度实际上会影响下拉列表的高度。
要获取控件的真实高度(以便您可以调整其他控件的大小),可以使用 GetWindowRect:
我不知道更改 Combo 控件本身的高度的好方法,坦率地说,我不相信这是可能的至少没有大量的子类化。因此,我实现了自己的组合式控件。
尽管它可能没有帮助,但您可能还想查看 GetComboBoxInfo() 函数,看看它是否提供了任何有用的信息。
ComboBoxes set the height of the control automatically, and as you've discovered, trying to set your own height actually affects the height of the drop-down list.
To get the real height of the control (so you can resize your other controls) you can use GetWindowRect:
I don't know of a good way to change the height of the Combo control itself, and frankly I don't believe it's possible at least without lots of subclassing. I have implemented my own combo-style control because of this.
Although it probably won't help, you may also like to have a look at the GetComboBoxInfo() function to see if that provides any useful information.