如何使用下拉列表而不是 ownerdraw 样式更改组合框控件的表观高度? [英] How to change the apparent height of a Combobox control with the dropdownlist but not ownerdraw style?

查看:18
本文介绍了如何使用下拉列表而不是 ownerdraw 样式更改组合框控件的表观高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:在某个对话框中,有多个控件排成一行.我希望它们都具有相同的外观高度.但是,对于具有 CBS_DROPDOWNLIST 样式且没有 CBS_OWNERDRAW* 的组合框,我无法更改表观高度.

Background: In a certain dialog there are several controls in a row. I would like all of them to have the same apparent height. However for a combobox with the CBS_DROPDOWNLIST style and no CBS_OWNERDRAW* I am having trouble changing the apparent height.

问题:如何更改此类 DROPDOWNLIST 组合框的外观高度?

Question: How can I change the apparent height of such a DROPDOWNLIST combobox?

我知道组合框不允许使用 SetWindowPos 更改高度.然而,我的印象是发送带有 wParam= -1 的 CB_SETITEMHEIGHT 消息应该修改高度.此方法确实适用于具有 CBS_OWNERDRAWFIXED 样式集的组合框(我想避免设置此样式以保留类似按钮"的外观).

I am aware that the combobox does not allow changing the height with SetWindowPos. I was however under the impression that sending a CB_SETITEMHEIGHT message with wParam= -1 should modify the height. This method does work for comboboxes with the CBS_OWNERDRAWFIXED style set (I wanted to avoid setting this style though to preserve the "button-like" look).

环境:我的 Win32 应用程序使用 Common-Controls 6.0,我担心启用视觉样式的环境(Windows 7、Aero)中的外观.

Environment: My Win32 application uses Common-Controls 6.0 and I am concerned about the appearance in an environment where visual styles are enabled (Windows 7, Aero).

推荐答案

我认为这不可能.

正如您所提到的,SetWindowPosMoveWindow 都不会像您期望的那样工作.那是因为 一个 ComboBox 的高度包括 drop 的高度-下.该控件根据其使用的字体大小自动调整自身大小.因此,要更改大小,请通过发送 WM_SETFONT 消息.

As you mention, neither SetWindowPos nor MoveWindow work like you expect. That's because the height of a ComboBox includes the height of the drop-down. The control automatically resizes itself according to the size of the font it uses. So to change the size, change the size of the control's font by sending it a WM_SETFONT message.

但我不明白为什么这是一个问题.您说您希望一系列控件具有相同的高度,但除非您要更改其他控件的高度,否则它们应该已经匹配.由于对话框上的所有控件通常使用相同的字体,因此组合框和文本框都应该具有相同的高度.当您使用 v6 的公共控件并启用视觉样式时,它们将应用于所有这些控件并且它们应该具有统一的外观.您不必手动调整高度.

But I don't understand why this is a problem. You say that you want a series of controls to have the same height, but unless you're changing the height of the other controls, they should already match. Since all controls on a dialog generally use the same font, combo boxes and text boxes should all have the same height already. When you use v6 of the common controls and Visual Styles are enabled, they'll be applied to all of these controls and they should have a uniform appearance. You shouldn't have to mess with the heights manually.

这篇关于如何使用下拉列表而不是 ownerdraw 样式更改组合框控件的表观高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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