当然这种方法是绕道而行.开发出来的软件肯定好看不了. 好了,让我们来引出下面这个很有用,比较专业的model吧. -------------------------------------------------------------------------------- option explicit private formoldwidth as long '保存窗体的原始宽度 private formoldheight as long '保存窗体的原始高度
'在调用resizeform前先调用本函数 public sub resizeinit(formname as form) dim obj as control formoldwidth = formname.scalewidth formoldheight = formname.scaleheight on error resume next for each obj in formname obj.tag = obj.left & " " & obj.top & " " & obj.width & " " & obj.height & " " next obj on error goto 0 end sub
'按比例改变表单内各元件的大小,在调用resizeform前先调用resizeinit函数 public sub resizeform(formname as form) dim pos(4) as double dim i as long, temppos as long, startpos as long dim obj as control dim scalex as double, scaley as double
scalex = formname.scalewidth / formoldwidth '保存窗体宽度缩放比例 scaley = formname.scaleheight / formoldheight '保存窗体高度缩放比例 on error resume next for each obj in formname startpos = 1 for i = 0 to 4 '读取控件的原始位置与大小 temppos = instr(startpos, obj.tag, " ", vbtextcompare) if temppos > 0 then pos(i) = mid(obj.tag, startpos, temppos - startpos) startpos = temppos + 1 else pos(i) = 0 end if '根据控件的原始位置及窗体改变大小的比例对控件重新定位与改变大小 obj.move pos(0) * scalex, pos(1) * scaley, pos(2) * scalex, pos(3) * scaley next i next obj on error goto 0 end sub
'开发软件时候,把这个modal装入程序中.然后加入如下代码: private sub form_load() call resizeinit(me) '在程序装入时必须加入 end sub
private sub form_resize() call resizeform(me) '确保窗体改变时控件随之改变 end sub --------------------------------------------------------------------------------