PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Text Scatter Effect-VBForums
Results 1 to 1 of 1

Thread: Text Scatter Effect

  1. #1

    Thread Starter
    Addicted Member NinjaNic's Avatar
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Text Scatter Effect

    Hi all! This is my first code bank submission. This VB 2010 code will use a timer and draw random text over the form. I thought it was kind of cool, but otherwise it' pretty useless. However, this is very customizable so maybe there can be a use for this?
    vb Code:
    1. Public Class Form1
    2.  
    3.     'EACH RANDOMTEXT HAS 3 PROPERTIES: TEXT, LOCATIONX, AND LOCATIONY.
    4.     'THIS IS AN EFFECT TO SCATTER TEXT TO SLOWLY COVER THE SCREEN.
    5.  
    6.     Dim R As New Random
    7.     Dim F As New Font("Arial", 16, FontStyle.Bold)
    8.     Dim RandomTexts As New List(Of RandomText)
    9.  
    10.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    11.         Timer1.Start()
    12.     End Sub
    13.  
    14.     Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    15.         For Each RandomText In RandomTexts
    16.             e.Graphics.DrawString(RandomText.Text, F, Brushes.Black, New Point(RandomText.LocationX, RandomText.LocationY))
    17.         Next
    18.     End Sub
    19.  
    20.     Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
    21.         Dim RT As New RandomText("", New Point(0, 0))
    22.         NewText(Me.ClientRectangle.Size)
    23.         RandomTexts.Add(RT)
    24.         Me.Text = "Text Scatter Effect. # of random texts: " & RandomTexts.Count
    25.         Me.Invalidate()
    26.     End Sub
    27.  
    28.     Private Sub NewText(ByRef ScreenSize As Point)
    29.         Dim Alphabet As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"
    30.         Dim N As Int32 = CInt(R.Next(3, 15))
    31.         Dim A As Int32 = CInt(R.Next(Alphabet.Length))
    32.         For Each RandomText In RandomTexts
    33.             If RandomText.Text = "" Then
    34.                 RandomText.LocationX = R.Next(-10, (ScreenSize.X - 10))
    35.                 RandomText.LocationY = R.Next(-10, (ScreenSize.Y - 10))
    36.                 Do Until N <= 0
    37.                     N -= 1
    38.                     RandomText.Text += Alphabet(A)
    39.                     A = CInt(R.Next(Alphabet.Length))
    40.                 Loop
    41.             End If
    42.         Next
    43.     End Sub
    44.  
    45. End Class
    46.  
    47. Public Class RandomText
    48.  
    49.     Public Property Text As String
    50.     Public Property LocationX As Int32
    51.     Public Property LocationY As Int32
    52.  
    53.     Public Sub New(ByRef TextNew As String, ByRef LocationNew As Point)
    54.  
    55.         Text = TextNew
    56.         LocationX = LocationNew.X
    57.         LocationY = LocationNew.Y
    58.  
    59.     End Sub
    60.  
    61. End Class
    (Edit: I give some credit to .paul. for helping me out a little!)
    Last edited by NinjaNic; Jan 5th, 2015 at 11:16 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width