delphi自动调整combobox下拉列表宽度(PostMessage CB_SETDROPPEDWIDTH)
在combobox所在的窗口的Formshow事件里调用即可
- procedure SetComboBoxListWidth( AComboBox: TComboBox );
- var
- i: Integer;
- nMaxLen, nMinWidth: integer;
- nFontWidth: Integer;
- nCboLeft: integer;
- ctlCustom: TControl;
- begin
- nCboLeft := AComboBox.Left;
- ctlCustom := AComboBox;
- with AComboBox do
- begin
- nFontWidth := Round( Abs(Font.Height / 2 ) );
- nMaxLen:= 0;
- for i:=0 to Items.Count-1 do
- begin
- if length(Items[i])* nFontWidth > nMaxLen then
- nMaxlen:= length(Items[i])* nFontWidth+5;
- end;
- if Items.Count > DropDownCount then
- nMaxLen := nMaxLen + 20;
- if nMaxLen > Width then
- begin
- if Items.Count>DropDownCount then
- begin
- SendMessage( Handle, CB_SETHORIZONTALEXTENT, nMaxLen+5, 0 );
- {解决分辨率小导致的ComboboxList的宽度超出屏幕}
- //while 部分是用来取出combobox控件相对与窗体的横坐标
- while not (ctlCustom.Parent is TForm) do
- begin
- nCboLeft := nCboLeft + ctlCustom.Parent.Left;
- ctlCustom := ctlCustom.Parent;
- end;
- nMinWidth := Min(400, nMaxLen); // 使用不大于nMaxLen的数做比较
- if (nCboLeft + nMinWidth) > Screen.Width-25 then // 不超出屏幕,并保留窗口滚动条宽度,约25
- nMinWidth := Screen.Width-25-nCboLeft;
- nMinWidth := Max(nMinWidth, Width); // 不小于控件自身宽度
- PostMessage(Handle, CB_SETDROPPEDWIDTH, nMinWidth, 0);
- end
- else
- PostMessage(Handle, CB_SETDROPPEDWIDTH, nMaxLen , 0);
- ShowHint := True;
- end
- else
- begin
- SendMessage( Handle, CB_SETHORIZONTALEXTENT, 0, 0 );
- PostMessage(Handle, CB_SETDROPPEDWIDTH, Width , 0);
- end;
- end;
- end;
http://blog.csdn.net/youthon/article/details/8179348
delphi自动调整combobox下拉列表宽度(PostMessage CB_SETDROPPEDWIDTH)的更多相关文章
- Qt Quick 常用元素:ComboBox(下拉列表) 与 ProgressBar(进度条)
一.ComboBox ComboBox,即下拉列表框,由一个列表框和一个标签控件(或编辑控件)组成.ComboBox 的下拉列表是使用 Menu 实现的,列表内的每个条目对应一个 Menultem. ...
- 发掘ListBox的潜力(一):自动调整横向滚动条宽度
<自绘ListBox的两种效果>一文帖出之后,从反馈信息来看,大家对这种小技巧还是很认同.接下来我将继续围绕ListBox写一系列的文章,进一步发掘ListBox的潜力,其中包括:自动调整 ...
- ExtJS ComboBox 下拉列表详细用法
ExtJS ComboBox 下拉列表详细用法 标签: combobox 2015-06-14 23:23 5171人阅读 评论(2) 收藏 举报 分类: ExtJS(32) 目录(?)[+] ...
- EasyUI combobox下拉列表实现搜索过滤(模糊匹配)
项目中的某个下拉列表长达200多个项,这么巨大的数量一个一个找眼镜都得看花,于是就得整了个搜索功能.看网上别人帖子有只能前缀匹配的方案,但只能前缀匹配的话用起来也不是很方便.于是就记录一下模糊匹配的方 ...
- 如何设置 ComboBox 下拉列表的高度或间距
ComboBox 的下拉列表部分总是很挤,看起不舒服,但是设置了 ItemHeight 没用,怎么办呢? 首先设置一个较大的 ItemHeight 值,比如 20: 然后设置 ComboBox 的 D ...
- delphi button 实现下拉列表
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
- easyui combobox下拉列表的多选值
html: <input id="cc" class="easyui-combobox" value="" data-options= ...
- 45. ExtJS ComboBox 下拉列表详细用法
转自:https://blog.csdn.net/luckypeng/article/details/46496151 ComboBox 是ExtJS中经常用到的控件,今天我们来讲一下它的一些用法. ...
- DataGridView列的宽度、行的高度自动调整
注意:DataGridView控件是从.NET Framework 2.0版本开始追加的. 介绍一下DataGridView列的宽度和行的高度,根据单元格或Header的内容(一般是内容全部被表示)自 ...
随机推荐
- Android 监听软键盘按键的三种方式
前言: 我们在Android手机上面有时候会遇到监听手机软键盘按键的时候,例如:我们在浏览器输入url完毕后可以点击软键盘右下角的“Go”按键加载url页面:在点击搜索框的时候,点击右下角的searc ...
- Cisco IOS images
Cisco IOS images for Dynamips - GNS3http://docs.gns3.com/1-kBrTplBltp9P3P-AigoMzlDO-ISyL1h3bYpOl5Q8m ...
- MFC 之 OnClose 与 OnCancel
在一个对话框其中.按下esc键 与 上面的红叉,默认都是调用OnCancel()函数. 如今我要在按下esc键盘后不关闭程序而是弹出一个对话框,可是这个时候点击红叉 程序也不会关闭,为了解决问题.我 ...
- 【b094&&z14】靶形数独
[问题描述] 小城和小华都是热爱数学的好学生,最近,他们不约而同地迷上了数独游戏,好胜的分们想用数独来一比高低.但普通的数独对他们来说都过于简单了,于是他们向Z博士请教,Z博士拿出了他最近发明的&qu ...
- 【codeforces 758B】Blown Garland
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- [Ramda] Eliminate Function Arguments (Point-Free Style) with Ramda's Converge
When doing comparisons inside of functions, you end of relying heavily on the argument passed into t ...
- 使用Spring Tool Suite (STS)新的工作空间无需再配置
在你的新的工作空间中找到比如 F:\java-wokespace\你的新的工作空间名称\.metadata\.plugins\org.eclipse.core.runtime\.settings 找到 ...
- 详细阐述Web开发中的图片上传问题
Web开发中,图片上传是一种极其常见的功能.但是呢,每次做上传,都花费了不少时间. 一个"小功能"花费我这么多时间,真心不愉快. So,要得认真分析下原因. 1.在最初学习Java ...
- MySQL分区表使用方法
原文:MySQL分区表使用方法 1. 确认MySQL服务器是否支持分区表 命令: show plugins; 2. MySQL分区表的特点 在逻辑上为一个表,在物理上存储在多个文件中 HASH分区(H ...
- 【非常高%】【codeforces 733B】Parade
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...