您的位置:程序门 -> vb -> 基础类



如何使组合框下接列表中的项目多于8个呢?默认只能显示8项。但是如何拉长些呢?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


如何使组合框下接列表中的项目多于8个呢?默认只能显示8项。但是如何拉长些呢?[已结贴,结贴人:ggyy66]
发表于:2007-08-23 10:55:24 楼主
如何使组合框下接列表中的项目多于8个呢?默认只能显示8项。但是如何拉长些呢?
----------
找了半天,也没找到,以前好象看到过,要通过api函数实现,可是如何做呢?
发表于:2007-08-23 12:49:171楼 得分:20
const   cb_getitemheight   =   &h154
const   cb_setitemheight   =   &h153
const   cb_showdropdown   =   &h14f
private   declare   function   sendmessage   lib   "user32 "   alias   "sendmessagea "   (byval   hwnd   as   long,   byval   wmsg   as   long,   byval   wparam   as   long,   lparam   as   any)   as   long
private   declare   function   movewindow   lib   "user32 "   (byval   hwnd   as   long,   byval   x   as   long,   byval   y   as   long,   byval   nwidth   as   long,   byval   nheight   as   long,   byval   brepaint   as   long)   as   long

private   sub   form_load()
        dim   i   as   long
        for   i   =   1   to   50
                combo1.additem   format(i,   "00000 ")
        next   i
        combo1.listindex   =   0
       
        dim   lngcmblineheiht   as   long
        dim   lngcountline   as   long
        me.scalemode   =   vbpixels
        with   combo1
                lngcmblineheiht   =   sendmessage(.hwnd,   cb_getitemheight,   0,   byval   0)
                '设定下拉共有几行
                lngcountline   =   25                 '行
                movewindow   .hwnd,   .left,   .top,   .width,   lngcmblineheiht   *   (lngcountline   +   2),   1
        end   with
end   sub
发表于:2007-08-23 13:56:182楼 得分:0
谢谢楼上的指导,我有了思路,现在我找到一个简单的方法,比如在窗体中,  
先声明movewindow函数,然后在窗体的load事件中用一句代码就能实现这个功能:  

private   declare   function   movewindow   lib   "user32 "   (byval   hwnd   as   long,   byval   x   as   long,   byval   y   as   long,   byval   nwidth   as   long,   byval   nheight   as   long,   byval   brepaint   as   long)   as   long  

'调用api函数设置组合框下位列表长度  
movewindow   cbogongyi.hwnd,   cbogongyi.left   /   15,   cbogongyi.top   /   15,   cbogongyi.width   /   15,   200,   1  

为什么要除以15呢,因为vb窗体默认是缇,可是api函数是以像素为单位的.  
所以长度就要转成像素.一缇=15像素    
发表于:2007-08-23 21:56:153楼 得分:0
上面说错了,1象素=15缇


快速检索

最新资讯
热门点击