在用vb制作软件封面和界面时经常要用到三维字体,一般的方法是先用专门的软件(如xara3d等)制作出三维字体的图片,然后再用图片框等控件显示出来。这样虽然简单,但其缺点有二:一是要额外增加控件和图片,这样势必会增加程序的大小;二是在vb中图片的加载速度不敢恭维。如能用vb直接编程制作出三维字体,岂不美哉!以下是本人的一点“小技”,请笑纳!
先在vb中新建一个“工程”,然后在窗体上放置四个command。以下是源程序:
先声明如下“通用变量”:
dim posx, posy as integer '文字的显示位置
dim txtwidth as integer '文字轮廓宽度
dim str as string '欲显示的文字
private sub command1_click() '显示凸起三维文字
dim i as integer
str = "显示凸起三维文字"
me.cls
me.forecolor = rgb(255, 255, 255)
for i = 1 to txtwidth
me.currentx = posx - i
me.currenty = posy - i
me.print str
next i
me.forecolor = rgb(0, 0, 0)
for i = 1 to txtwidth
me.currentx = posx + i
me.currenty = posy + i
me.print str
next i
me.forecolor = rgb(0, 0, 255)
me.currentx = posx
me.currenty = posy
me.print str
end sub
private sub command2_click() '显示凹陷三维文字
dim i as integer
str = "显示凹陷三维文字"
me.cls
me.forecolor = rgb(0, 0, 0)
for i = 1 to txtwidth
me.currentx = posx - i
me.currenty = posy - i
me.print str
next i
me.forecolor = rgb(255, 255, 255)
for i = 1 to txtwidth
me.currentx = posx + i
me.currenty = posy + i
me.print str
next i
me.forecolor = rgb(0, 0, 255)
me.currentx = posx
me.currenty = posy
me.print str
end sub
private sub command3_click() '显示阴影三维文字
str = "显示阴影三维文字"
me.cls
me.forecolor = rgb(100, 100, 100)
me.currentx = posx + txtwidth
me.currenty = posy + txtwidth
me.print str
me.forecolor = rgb(0, 0, 255)
me.currentx = posx
me.currenty = posy
me.print str
end sub
private sub command4_click() '显示倾斜三维文字
dim i as integer
str = "显示倾斜三维文字"
me.cls
me.forecolor = rgb(100, 100, 100)
for i = 1 to txtwidth
me.currentx = x + i
me.currenty = y + i
me.print str
next i
me.forecolor = rgb(0, 0, 255)
me.currentx = posx
me.currenty = posy
me.print str
end sub
private sub form_load()
posx = 100
posy = 100
txtwidth = 50
me.fontsize = 30
end sub
以上程序在win98/vb6.0/233下调试通过。