用VB制作三维字体

类别:VB语言 点击:0 评论:0 推荐:

       在用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下调试通过。

 

 

本文地址:http://com.8s8s.com/it/it6824.htm