这是一个类模块:
1. 建立一个新的类模块,加入下列代码,并给类模块起名(例:autosize)
2. 加入一个窗口并且加入:private el as new autosize
3. 在 form_load 事件中加入 el.init me
4. 在 form_resize 事件中加入 el.formresize me
option explicit private nformheight as integer private nformwidth as integer private nnumofcontrols as integer private ntop() as integer private nleft() as integer private nheight() as integer private nwidth() as integer private nfontsize() as integer private nrightmargin() as integer private bfirsttime as boolean
sub init(frm as form, optional nwindstate as variant) dim i as integer dim bwinmax as boolean bwinmax = not ismissing(nwindstate) nformheight = frm.height nformwidth = frm.width nnumofcontrols = frm.controls.count - 1 bfirsttime = true redim ntop(nnumofcontrols) redim nleft(nnumofcontrols) redim nheight(nnumofcontrols) redim nwidth(nnumofcontrols) redim nfontsize(nnumofcontrols) redim nrightmargin(nnumofcontrols) on error resume next for i = 0 to nnumofcontrols if typeof frm.controls(i) is line then ntop(i) = frm.controls(i).y1 nleft(i) = frm.controls(i).x1 nheight(i) = frm.controls(i).y2 nwidth