Show 3D Text in your Visual Basic programs

Discussion in 'Visual Basic [VB]' started by pradeep, Apr 18, 2007.

  1. pradeep

    pradeep Team Leader

    Apr 4, 2005
    Likes Received:
    Trophy Points:
    Kolkata, India
    Home Page:
    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):

    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:
    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)
    	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:

    .ForeColor = RGB(256 - i * 2, 256 - i * 2, 256 - i * 2) 
    This code varies the colour from blue to red:

    .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.
  2. nikk1986

    nikk1986 New Member

    Jan 19, 2009
    Likes Received:
    Trophy Points:
    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?

  3. skp819

    skp819 New Member

    Dec 8, 2008
    Likes Received:
    Trophy Points:

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice