Introduction.
We have explored several label animation methods in the previous posts, and now we will try another trick using the last design you created: the Zoom-in method.
In this method, we add a splash of color—each letter of the employee’s name is assigned a randomly generated color. The letters are plotted in a “magical” sequence: odd-numbered letters appear first on odd-numbered labels (lbl01, lbl03, lbl05, etc.), followed by even-numbered letters on even-numbered labels (lbl02, lbl04, lbl06, etc.). The letters are displayed at fixed time intervals, creating a smooth animated effect.
After these two steps, the employee’s name is fully displayed in the form header, producing an eye-catching Zoom-in animation.
If you have tried the earlier label animation methods from last week, implementing this technique will be straightforward and easy to follow.
The Design Task.
Make a Copy of the Employees Form, which we designed last week, and name it Employees_2 or any other name you prefer.
The sample design of the Form, with twenty labels placed close together in the Header of the Form, with the Name Property Values set as lbl01 to lbl20, is given below:
Display the Code Module of the Form (View -> Code) after opening the Form in Design View.
Copy and paste the following VBA Code into the Form Module, overwriting the existing Code.
The Form Module Code.
Option Compare Database Option Explicit Dim j, txtName, ctrl As Label Private Sub Form_Current() Dim t, m, R, G, B Randomize (Timer) txtName = Me![first name] & " " & Me![Last name] For j = 1 To 20 Set ctrl = Me("lbl" & Format(j, "00")) ctrl.Caption = "" Next For j = 1 To Len(txtName) Step 2 Set ctrl = Me("lbl" & Format(j, "00")) R = Int(Rnd(1) * 64) G = Int(Rnd(1) * 128) B = Int(Rnd(1) * 255) ctrl.ForeColor = RGB(R, G, B) ctrl.Caption = Mid(txtName, j, 1) t = Timer Do While Timer < t + 0.1 DoEvents Loop Next For j = 2 To Len(txtName) Step 2 Set ctrl = Me("lbl" & Format(j, "00")) R = Int(Rnd(1) * 255) G = Int(Rnd(1) * 128) B = Int(Rnd(1) * 64) ctrl.ForeColor = RGB(R, G, B) ctrl.Caption = Mid(txtName, j, 1) t = Timer Do While Timer < t + 0.1 DoEvents Loop Next End Sub
Save the Form with the new VBA Code.
The Demo Run.
Open the Form in the normal view.
Use the record navigation button to move the record forward or back and watch how the employee name is displayed in the header labels.
The sample screen in Normal View is given below:
-
0.5 will slow down the animation.
-
0.05 will make it run faster.
- Textbox and Label Inner Margins
- Animating Label on Search Success
- Label Animation Style-1
- Label Animation Style-2
- Label Animation Variant
- Label Animation Zoom-in Style
- Label Animation in Colors
- Label Animation Zoom-out Fade
Each character of the name is displayed in a different color at a 0.1-second interval, creating a smooth animated effect. The color codes are generated randomly.
In this program, we use two delay loops instead of the form’s default Timer Interval event procedure.
You can adjust the animation speed by modifying the value in the line:
For example:
This gives you full control over the speed of the Zoom-in effect.
[...] This post was mentioned on Twitter by aprpillai. aprpillai said: Label Animation in Colors: We have learned several label animation methods, through last few http://goo.gl/fb/PPMy6 [...]
ReplyDelete