您的位置:程序门 -> vb -> 网络编程



窗体大小随着屏幕大小变化


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


窗体大小随着屏幕大小变化
发表于:2007-11-28 15:49:28 楼主
用vb做出来的一个软件没考虑屏幕显示大小的问题,设计的时候用的是17宽屏,现在好多电脑都用不了.请问如果将窗体大小随着屏幕大小变化,菜鸟求助,谢谢!!
发表于:2007-11-28 16:13:271楼 得分:0
有些控件我已经知道如何设置了,方法如下:
option   explicit
private   initwidth   as   long               '   form   的原始大小
private   initheight   as   long

private   sub   form_load()
initwidth   =   scalewidth
initheight   =   scaleheight
dim   ctl   as   control
'   记录每个   control   的原始位置、大小、字型大小,   放在   tag   属性中
on   error   resume   next   '确保left,   top,   width,   height,   tag属性没有全有的control
for   each   ctl   in   me       '也能正常执行
        ctl.tag   =   ctl.left   &   "   "   &   ctl.top   &   "   "   &   ctl.width   &   "   "   &   ctl.height   &   "   "
        ctl.tag   =   ctl.tag   &   ctl.fontsize   &   "   "
next   ctl
on   error   goto   0
end   sub

private   sub   form_resize()
dim   d(4)   as   double
dim   i   as   long
dim   temppos   as   long
dim   startpos   as   long
dim   ctl   as   control
dim   tempvisible   as   boolean
dim   scalex   as   double
dim   scaley   as   double

scalex   =   scalewidth   /   initwidth
scaley   =   scaleheight   /   initheight
on   error   resume   next
for   each   ctl   in   me
        tempvisible   =   ctl.visible
        ctl.visible   =   false
        startpos   =   1
        '   读取   control   的原始位置、大小、字型大小
        for   i   =   0   to   4
                temppos   =   instr(startpos,   ctl.tag,   "   ",   vbtextcompare)
                if   temppos   >   0   then
                        d(i)   =   mid(ctl.tag,   startpos,   temppos   -   startpos)
                        startpos   =   temppos   +   1
                else
                        d(i)   =   0
                end   if
                '   根据比例设定   control   的位置、大小、字型大小
                ctl.move   d(0)   *   scalex,   d(1)   *   scaley,   d(2)   *   scalex,   d(3)   *   scaley
                'ctl.width   =   d(2)   *   scalex
                'ctl.height   =   d(3)   *   scaley
                if   scalex   <   scaley   then
                        ctl.fontsize   =   d(4)   *   scalex
                else
                        ctl.fontsize   =   d(4)   *   scaley
                end   if
        next   i
        ctl.visible   =   tempvisible
next   ctl
on   error   goto   0
end   sub

但在某些物件上不能使用,例如:line,因为它没有top,   left
width,   height所以在本程式中没有作用.求助高手指点下这种控件该如何设置
发表于:2007-11-28 16:38:352楼 得分:0
用screen.width   screen.height取得屏幕大小,然后按比例计算你的窗口大小
发表于:2007-11-28 16:58:543楼 得分:0
直接设form1.windowstate=vbmaximized就可以了
发表于:2007-11-28 17:07:264楼 得分:0
2楼正解
发表于:2007-11-28 17:11:475楼 得分:0
screen的大小可是覆盖了任务栏的!


快速检索

最新资讯
热门点击