1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Show 3D Text in your Visual Basic programs

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

  1. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    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):

    Code:
    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:
    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:
    .ForeColor = RGB(256 - i * 2, 256 - i * 2, 256 - i * 2) 
    This code varies the colour from blue to red:

    Code:
    .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

    Joined:
    Jan 19, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  3. skp819

    skp819 New Member

    Joined:
    Dec 8, 2008
    Messages:
    89
    Likes Received:
    3
    Trophy Points:
    0

Share This Page