At this point, you have classes you can use to create and store messages in the user’s folder on the current system as described in Exploring the TypingBuddy Application (Part 4). These messages appear whenever the typing time is over in TypingBuddy. Of course, you need some way to display the messages. That’s the responsibility of frmMessage described in Exploring the TypingBuddy Application (Part 2).
One of the requirements for frmMessage is flexibility. The developer has a number of requirements for formatting the message box to convey information in the way the user wants to see it. In order to meet this requirement, frmMessage includes a number of constructors as shown here.
All of the constructors require RestTime as input. This is the amount of time that the user must do something other than working at the computer (based on whatever messages the user has configured or using the default message). The code uses this input to initialize RemainingTime, which contains the amount of time remaining to rest. When working with the simplest constructor, the code sets btnContinue.Enabled to false so that the user must wait to clear the message box. It also sets btnContinue.Text to the initial resting time value. The code then starts the timer by calling RestTimer.Start().
Beyond this simple setup, the developer can also choose to provide additional information. For example, supplying the Boolean value, ShowIcon, determines whether frmMessage displays an icon when displayed. The String value, Message, contains a custom message that the user has defined. Otherwise, frmMessage displays a default message to the user. The developer can also choose to provide a custom title for the message box by supplying the String value, Title. The constructors can accept various combinations of these three inputs, or provide all of them.
Once the timer is started, it counts down the time for the rest period. The Timer control, RestTime performs this task for you. The Tick() event handler code is as shown here.
During the countdown phase, the value of RemainingTime is decremented. The code then displays the new number of seconds in btnContinue.Text so the user can see it on screen. When RemainingTime reaches 0, the code calls RestTimer.Stop() to stop the timer. It then changes btnContinue.Text to “&Continue” (with the C underlined) and btnContinue.Enable to true so that the user can click the Continue button.
The code for the Continue and Quit Click() event handlers simply closes the form. The reaction differs based on the button the user clicks, but this is handled by frmMain.
Next we’ll you’ll see the code used to add and edit messages. This information is handled by frmAddEdit. In the meantime, let me know if you have questions about the TypingBuddy application code you’ve seen today at John@JohnMuellerBooks.com. You can see the next post in this series at Exploring the TypingBuddy Application (Part 6).