Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Visual Basic [VB] (http://www.go4expert.com/articles/visual-basic-tutorials/)
-   -   Show 3D Text in your Visual Basic programs (http://www.go4expert.com/articles/3d-text-visual-basic-programs-t3922/)

pradeep 18Apr2007 17:46

Show 3D Text in your Visual Basic programs
 
Visual Basic 6.0 offers plenty of tools for displaying regular text, but what if you want special effects? This article shows you how to display 3-D text in your program.

The Windows API's TextOut function displays text on the screen. The declaration is as follows (place this in a module in your program):

Code: VB

Public Declare Function TextOut Lib "gdi32" Alias _
    "TextOutA" (ByVal hdc As Long, ByVal x As Long, _
    ByVal y As Long, ByVal lpString As String, ByVal _
    nCount As Long) As Long

Here are the arguments:
  • hdc is the device context of the destination.
  • x and y are the coordinates of the location to display the text.
  • lpString is the text to display.
  • nCount is the length of the string.
A device context is the way Windows represents certain display objects. In Visual Basic, only forms, Picture Box controls, and the printers have a device context, which means this technique is limited to displaying 3-D text on those objects.

The technique used here to display 3-D text is to output the string repeatedly at slightly different, overlapping locations. By varying the colour of the text with each iteration, you obtain a 3-D effect. Here's an example:
Code: VB

Private Sub Command1_Click()
   
    Dim i As Integer
    Dim s As String
   
    With Form1
        s = "Text to display"
        For i = 0 To 127
            .Font.Name = "Times New Roman"
            .Font.Size = 36
            .ForeColor = RGB(i * 2, i * 2, i * 2)
            TextOut .hdc, i / 15, i / 15, s, Len(s)
        Next
    End With
End Sub

You can see that the text is output 128 times. Each time, the position shifts down slightly and to the right, and the colour changes. In the entire process, the colour changes from black or RGB(0, 0, 0) to essentially white or RGB(254, 254, 254). You could get a different but equally effective result by varying the colour from white to black by changing this single line of code:

Code: VB

.ForeColor = RGB(256 - i * 2, 256 - i * 2, 256 - i * 2)

This code varies the colour from blue to red:

Code: VB

.ForeColor = RGB(i * 2, 0, 256 - i * 2)

There are lots of attractive effects available with this technique. Its recommended that you experiment until you get just what you want.

nikk1986 21Jan2009 15:33

Re: Show 3D Text in your Visual Basic programs
 
Hiiiiiii
Pradeep Ji,
i wanna know whats max size of textbox in vb6.0
actually i wanna show a long size file in text.......


but i faced sum problem .
can u resolve my problem?

-Nikk
9873307397

skp819 28Jan2009 14:19

Re: Show 3D Text in your Visual Basic programs
 
here we can also find the source code for that.
http://www.thescarms.com/vbasic/3dtext.aspx
but here is explained in better way.


All times are GMT +5.5. The time now is 20:24.