source code 3d text

Download Source Code 3D Text

If you can't read please download the document

Upload: gilang-on-wp

Post on 15-Jan-2016

4 views

Category:

Documents


2 download

DESCRIPTION

VB6

TRANSCRIPT

Display 3-D Text on a FormVisual Basic has plenty of tools for displaying regular text, but what if you want special effects? This tip shows you how to display 3-D text in your program.The Windows API has a function TextOut that 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 LongThe arguments are:- hdc is the device context of the destination (more on this soon).- 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, so that 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 color of the text with each iteration, a 3-D effect is obtained. Here's an example.Private Sub Command1_Click()Dim i As IntegerDim s As StringWith Form1s = "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)NextEnd WithEnd SubYou can see that the text is output 128 times. Each time, the position is shifted slightly down and to the right, and the color is changed. In the entire process, the color changes from RGB(0, 0, 0), or black, to RGB(254, 254, 254), or essentially white. You could get a different but equally effective result by varying the color from white to black by changing a single line of code as follows:.ForeColor = RGB(256 - i * 2, 256 - i * 2, 256 - i * 2)This code varies the color from blue to red:.ForeColor = RGB(i * 2, 0, 256 - i * 2)There are lots of attractive effects available with this technique. I recommend that you experiment until you get just what you want.