How to Draw Rainbow Text in Picture Box
Posted on January 5, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | 'Graphics - How to Draw Rainbow Text in Picture Box Option Explicit 'Add a Picture Box a Label and a Command Button to your form. Dim strWidth As Long Const CharSpace = 5 Dim LineSpace As Long Dim CurLine As Integer Public Sub RainbowText(ByVal sText As String, Colour As OLE_COLOR, Line As Integer) If CurLine <> Line Then CurLine = Line strWidth = 0 End If With Picture1 .CurrentX = strWidth .CurrentY = (Line - 1) * LineSpace .ForeColor = Colour .Print sText End With Label1.Caption = sText strWidth = strWidth + Label1.Width + Char End Sub Private Sub Command1_Click() Call RainbowText("http://", vbRed, 1) Call RainbowText("code", vbGreen, 1) Call RainbowText("it", vbYellow, 2) Call RainbowText("better.com", vbBlack, 2) End Sub Private Sub Form_Load() With Picture1 .fontname = "Arial" .Fontsize = 20 .FontBold = True .FontItalic = False .FontUnderline = False .FontStrikethru = False End With With Label1 .AutoSize = True .Visible = False .Font = Picture1.Font .fontname = Picture1.fontname .FontBold = Picture1.FontBold .FontItalic = Picture1.FontItalic .Fontsize = Picture1.Fontsize .FontStrikethru = Picture1.FontStrikethru .FontUnderline = Picture1.FontUnderline Label1.Caption = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" LineSpace = .Height + 10 strWidth = 0 CurLine = 1 End With End Sub |