让标题栏文字居中
|添加以下模块:
publicsubcenterc(frmasform)
dimspcfasinteger'howmanyspacescanfit
dimclenasinteger'captionlength
dimoldcasstring'oldcaption
dimiasinteger'notimportant
''removeanyspacesattheendsofthecaption
''veryeasyifyoureaditcarefully
oldc=frm.caption
dowhileleft(oldc,1)=space(1)
doevents
oldc=right(oldc,len(oldc)-1)
loop
dowhileright(oldc,1)=space(1)
doevents
oldc=left(oldc,len(oldc)-1)
loop
clen=len(oldc)
ifinstr(oldc,"!")<>0then
ifinstr(oldc,"")<>0then
clen=clen*1.5
else
clen=clen*1.4
endif
else
ifinstr(oldc,"")<>0then
clen=clen*1.4
else
clen=clen*1.3
endif
endif
'''seehowmanycharacterscanfit
spcf=frm.width/61.2244''howmanyspacecanfit itthecaption
spcf=spcf-clen'howmanyspacescanfit-howmuch spacethe
''captiontakesup
'''nowthetrickypart
ifspcf>1then
doevents'speeduptheprogram
frm.caption=space(int(spcf/2))+oldc
else'iftheformistoosmallforspaces
frm.caption=oldc
endif
endsub
|在窗体中添加以下代码:
dimoldsizeaslong
privatesubform_resize()
ifme.width=oldsizethen'ifthewidthhasn't changed
exitsub'thendontmesswithit
else
centercme
oldsize=me.width
endif
endsub
privatesubform_load()
centercme
oldsize=me.width
endsub