在combobox所在的窗口的Formshow事件里调用即可

  1. procedure SetComboBoxListWidth( AComboBox: TComboBox );
  2. var
  3. i: Integer;
  4. nMaxLen, nMinWidth: integer;
  5. nFontWidth: Integer;
  6. nCboLeft: integer;
  7. ctlCustom: TControl;
  8. begin
  9. nCboLeft := AComboBox.Left;
  10. ctlCustom := AComboBox;
  11. with AComboBox do
  12. begin
  13. nFontWidth := Round( Abs(Font.Height / 2 ) );
  14. nMaxLen:= 0;
  15. for i:=0 to Items.Count-1 do
  16. begin
  17. if length(Items[i])* nFontWidth > nMaxLen then
  18. nMaxlen:= length(Items[i])* nFontWidth+5;
  19. end;
  20. if Items.Count > DropDownCount then
  21. nMaxLen := nMaxLen + 20;
  22. if nMaxLen > Width then
  23. begin
  24. if Items.Count>DropDownCount then
  25. begin
  26. SendMessage( Handle, CB_SETHORIZONTALEXTENT, nMaxLen+5, 0 );
  27. {解决分辨率小导致的ComboboxList的宽度超出屏幕}
  28. //while 部分是用来取出combobox控件相对与窗体的横坐标
  29. while not (ctlCustom.Parent is TForm) do
  30. begin
  31. nCboLeft := nCboLeft + ctlCustom.Parent.Left;
  32. ctlCustom := ctlCustom.Parent;
  33. end;
  34. nMinWidth := Min(400, nMaxLen);                      // 使用不大于nMaxLen的数做比较
  35. if (nCboLeft + nMinWidth) > Screen.Width-25 then     // 不超出屏幕,并保留窗口滚动条宽度,约25
  36. nMinWidth := Screen.Width-25-nCboLeft;
  37. nMinWidth := Max(nMinWidth, Width);                  // 不小于控件自身宽度
  38. PostMessage(Handle, CB_SETDROPPEDWIDTH, nMinWidth, 0);
  39. end
  40. else
  41. PostMessage(Handle, CB_SETDROPPEDWIDTH, nMaxLen , 0);
  42. ShowHint := True;
  43. end
  44. else
  45. begin
  46. SendMessage( Handle, CB_SETHORIZONTALEXTENT, 0, 0 );
  47. PostMessage(Handle, CB_SETDROPPEDWIDTH, Width , 0);
  48. end;
  49. end;
  50. end;

http://blog.csdn.net/youthon/article/details/8179348

delphi自动调整combobox下拉列表宽度(PostMessage CB_SETDROPPEDWIDTH)的更多相关文章

  1. Qt Quick 常用元素:ComboBox(下拉列表) 与 ProgressBar(进度条)

    一.ComboBox ComboBox,即下拉列表框,由一个列表框和一个标签控件(或编辑控件)组成.ComboBox 的下拉列表是使用 Menu 实现的,列表内的每个条目对应一个 Menultem. ...

  2. 发掘ListBox的潜力(一):自动调整横向滚动条宽度

    <自绘ListBox的两种效果>一文帖出之后,从反馈信息来看,大家对这种小技巧还是很认同.接下来我将继续围绕ListBox写一系列的文章,进一步发掘ListBox的潜力,其中包括:自动调整 ...

  3. ExtJS ComboBox 下拉列表详细用法

    ExtJS ComboBox 下拉列表详细用法 标签: combobox 2015-06-14 23:23 5171人阅读 评论(2) 收藏 举报  分类: ExtJS(32)    目录(?)[+] ...

  4. EasyUI combobox下拉列表实现搜索过滤(模糊匹配)

    项目中的某个下拉列表长达200多个项,这么巨大的数量一个一个找眼镜都得看花,于是就得整了个搜索功能.看网上别人帖子有只能前缀匹配的方案,但只能前缀匹配的话用起来也不是很方便.于是就记录一下模糊匹配的方 ...

  5. 如何设置 ComboBox 下拉列表的高度或间距

    ComboBox 的下拉列表部分总是很挤,看起不舒服,但是设置了 ItemHeight 没用,怎么办呢? 首先设置一个较大的 ItemHeight 值,比如 20: 然后设置 ComboBox 的 D ...

  6. delphi button 实现下拉列表

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  7. easyui combobox下拉列表的多选值

    html: <input id="cc" class="easyui-combobox" value="" data-options= ...

  8. 45. ExtJS ComboBox 下拉列表详细用法

    转自:https://blog.csdn.net/luckypeng/article/details/46496151 ComboBox 是ExtJS中经常用到的控件,今天我们来讲一下它的一些用法. ...

  9. DataGridView列的宽度、行的高度自动调整

    注意:DataGridView控件是从.NET Framework 2.0版本开始追加的. 介绍一下DataGridView列的宽度和行的高度,根据单元格或Header的内容(一般是内容全部被表示)自 ...

随机推荐

  1. margin隐藏最后的切割线

    <style> *{margin: 0;padding: 0;} #demo li{ border-bottom: 1px solid #ccc; } #demo ul{ margin-b ...

  2. Android 报错 Error:(303, 27) 错误: 找不到符号 符号: 方法 sin(float) 位置: 类 FloatMath

    今天更新了sdk,升级到Android SDK 23.发现Android studio用23编译 SlidingMenu时出错,错误如下: 报错的地方这这里: float distanceInflue ...

  3. 设置好ftp后用xftp连接提示无法打开,无法显示远程文件夹

    原文:设置好ftp后用xftp连接提示无法打开,无法显示远程文件夹 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/the_victory/artic ...

  4. 【codeforces 757C】Felicity is Coming!

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. [Angular] USING ZONES IN ANGULAR FOR BETTER PERFORMANCE

    Link to the artical. Zone detects any async opreations. Once an async oprations happens in Angular, ...

  6. Lucene + Pinyin4J 提供首字母搜索(——)

    遇到一个集团需求,要求在地址查询时候提供拼音搜索,第一反应应该不难,不过实现过程中却一波三折. 1.第一步是讲字段首字母进行索引,具体可以使用Pinyin4j提供的方法完成. 2.原来系统用的luce ...

  7. Erlang 命令行监控工具

    http://www.cnblogs.com/me-sa/archive/2012/11/22/erlang_vm_monitor_text_mode.html 之前介绍过一个Erlang的Web监控 ...

  8. 【codeforces 777A】Shell Game

    [题目链接]:http://codeforces.com/contest/777/problem/A [题意] 奇数次操作交换1,2位置的东西; 偶数此操作交换2,3位置的东西 给你操作的次数,和最后 ...

  9. spark cogroup算子

    java /** *cogroup与join算子不同的是如果rdd中的一个key,对应多个value,则返回<Iterable<key>,Iterable<value>& ...

  10. p2p-如何拯救k8s镜像分发的阿喀琉斯之踵

    K8s的出现为PaaS行业的发展打了一针兴奋剂,Docker+k8s的技术路线已经成为了容器云的主流.尤其针对大流量,大弹性的应用场景来说,k8s将其从繁杂的运维.部署工作中彻底拯救出来.然而事情往往 ...