Introduction.
This week, we will explore a different style of label animation technique. If you would like to revisit the earlier, simpler label animation methods, the links to those pages are provided below.In all the earlier methods, we used two labels moving toward each other from opposite directions, coming together to form text that appeared like a 3D heading.
This week, we will take a different approach. For this method, you will need about twenty small labels placed close together in a horizontal line. Each label will display a single character of the employee’s name. Since all employee names are fewer than twenty characters, this arrangement will be sufficient.
A sample layout of the labels in Design View is shown below:
Animation Style image.
The employee’s name will appear from left to right, one character at a time, across the labels. After the full name is displayed, the letters will zoom in and zoom out sequentially, creating a dynamic animated effect.
The screenshot above was captured live of this action.
The Design Task.
Let us complete the design task of this animation.
If you have not explored the earlier examples, then import the Employees Table from the Northwind sample database.
Click on the Employees Table and select Form from the Insert Menu.
Create a Form as shown above and save it with the name Employees.
Open the Form in Design View.
Select the Label Tool from the Toolbox and draw a Label control in the header section of the Form.
Change the following property values of the Label as given below:
- Name = lbl01
- Width = 0.2528"
- Height = 0.3549"
- Top = 0.1563"
- Left = 1.1146
- Back Style = Transparent
- Border Style = Transparent
- Special Effect = Flat
- Font Name = Verdana
- Font Size = 14
- Font Weight = Bold
- ForeColor = 7500402
Now, we must copy this label nineteen times and arrange them as shown in the first image, at the top of this page.
We must also change the Name Property Value of each label sequentially so that we can easily address each label in Programs to change their caption values to display the Employee's name.
Right-click on the Label and select Copy from the displayed Shortcut Menu.
Select Paste from the Edit Menu to create a copy of the Label.
Click and drag the new label to place it to the right of the first label. Don't worry about the misalignment of the labels; we will arrange them easily later.
Repeat the Paste action to create another eighteen labels.
The Labels will appear automatically to the right of earlier labels.
Click on the second Label.
Display its Property Sheet (View -> Properties).
Change the Name Property value to lbl02.
Repeat this method for other labels, naming them sequentially as lbl03, lbl04, and so on up to lbl20.
Click on the left side of the first label (lbl01) and drag the Mouse over all twenty labels to select them all together.
Select Format -> Align -> Top to align all Labels horizontally.
Select Format -> Align -> Left to bring all the Labels close together.
Now that we have arranged the labels and their Name Property Values set to lbl01 to lbl20, all that is left to do is to copy the following Programs into the Form's Code Module.
Select Code from the View Menu.
Copy and paste the following VBA Code into the Module (overwriting the existing VBA Code, if any).
The Form Module Code.
Option Compare Database Option Explicit Private Const twips As Long = 1440 Dim i, j, txtName, ctrl As Label Private Sub Form_Current() txtName = UCase(Me![first name] & " " & Me![Last name]) i = 0 Me.TimerInterval = 50 End Sub Private Sub Form_Timer() Dim m, L1, L2 i = i + 1 If i > Len(txtName) Then For j = Len(txtName) + 1 To 20 Set ctrl = Me("lbl" & Format(j, "00")) ctrl.Caption = "" Next Me.TimerInterval = 0 i = 0 animate Else Set ctrl = Me("lbl" & Format(i, "00")) ctrl.Caption = Mid(txtName, i, 1) ctrl.ForeColor = &H727272 End If DoEvents End Sub Public Function animate() Dim k As Integer, t For k = 1 To Len(txtName) Set ctrl = Me("lbl" & Format(k, "00")) ctrl.ForeColor = 0 ctrl.FontSize = 24 DoEvents If k = 10 Then Exit For t = Timer Do While Timer < t + 0.09 DoEvents Loop ctrl.FontSize = 14 Next End Function
The Trial Run.
Save the Form with the Code.
Open it in the normal view.
Use the Record Navigation Buttons to move the record forward/back and display the employee name in animated form.
Hope you like this method better and implement it in your Projects.
[...] This post was mentioned on Twitter by aprpillai. aprpillai said: Label Animation Zoom-in Style: This week we will learn a different style of Label Animation http://goo.gl/fb/RvFPT [...]
ReplyDelete