Page 1
Page 2
Listing 2 Option Explicit
'
Property defining length in msec to show popup
Public DisplayTime As Integer
' Text to display
Public Text As String
' Should autohide be enabled
Public AutoHide As Boolean
Private Sub Form_Load()
' Set our defaults for the message box
DisplayTime = 500
Text = ""
Me.Caption = "Message Box"
AutoHide = False
Timer1.Interval
= DisplayTime
Call DisableAutoHide
Me.Top = 500
Me.Left = 100
End Sub
' When user selects the Checkbox, toggle the values
Private Sub Check1_Click()
If Check1.Value = 0 Then
Call DisableAutoHide
Else
Call EnableAutoHide
End If
End Sub
' Method
to change the display text
Public Sub SetDisplayText(ByVal str As String)
Text = str
message.Caption = str
End Sub
' Method
to change window caption
Public Sub SetWindowCaption(ByVal str As String)
Me.Caption = str
End Sub
' When user clicks form, disable
autohide
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X
As Single, Y As Single)
Call DisableAutoHide
End Sub
'
When user clicks on message, disable autohide
Private Sub message_Click()
Call DisableAutoHide
End Sub
' Hide the form when user
selects OK
Private Sub Form_OKClick()
Me.Hide
End Sub
'
Hide form when user selects checkbox label
Private Sub Label2_Click()
If AutoHide Then
Call DisableAutoHide
End If
End Sub
'
Method to set the timer length
Public Sub SetTimerLength(ByVal val As Integer)
' Good place to add limits!
Timer1.Interval = val
End Sub
'
Method to change autohide state
Public Sub SetAutoHide(ByVal ahide As Boolean)
If ahide = True Then
Call EnableAutoHide
Else
Call DisableAutoHide
End If
End Sub
' Handle timer event
Private Sub
Timer1_Timer()
' if we are to autohide, then hide the form
If AutoHide
Then
Me.Hide
Timer1.Enabled = False
End If
End Sub
'
Method to display a message with one call
Public Sub DisplayMessage(ByVal
mess As String, ByVal Caption As String)
Me.Caption = Caption
Text = mess
Call Display
End Sub
' Method to display with current
properties
Public Sub Display()
message.Caption = Text
Timer1.Enabled
= AutoHide
Timer1.Interval = DisplayTime
Call SetAutoHide(AutoHide)
Me.Show
End Sub
' Helper sub to disable autohide
Private Sub DisableAutoHide()
AutoHide = False
Timer1.Enabled = False
Check1.Value = 0
End Sub
' Helper sub to enable autohide
Private Sub EnableAutoHide()
AutoHide = True
Timer1.Enabled = True
Check1.Value = 1
End Sub
There are only a
couple of important subroutines, while most of the subroutines support accepting
parameters. The Check1_click event is used to change the state of auto-hiding
and calls the enable or disable subroutines as appropriate. The Display subroutine
does the bulk of the work by setting the parameters for the controls, setting
the timer length, and finally displaying the message box. Finally, when the Timer1_Timer
event fires we hide the display and turn off the timer.
One
of the challenges was to allow the user to cancel auto-hiding when they want to.
Although, our application could provide a configuration page (and probably should)
with this item on it, I wanted to give a more immediate method. To accomplish
this, we allow the user to tap on the message form to turn off auto-hiding. This
is tricky, so I capture the mouse down events for each element on our form and
the form as well. Anytime anything is tapped when the display is active we disable
hiding by calling the DisableAutoHide routine.
That's
it; we now have a simple popup form we could use for status updates (e.g. "Save
Complete") or results of an operation. This simple application could be enhanced
in several ways. We could add an Image object and add graphics similar to those
found when using the eVB MsgBox command. I also thought sound would be important
to let the user know a message box appeared. Finally, I think keeping a history
of messages displayed would be a useful addition. If the user missed a message
that they wanted to review, the application could display the message box with
auto-hiding off and a scrolling list, allowing the user to scroll through old
messages.
Now it's your turn: What do you think are some
of areas where we can improve the usability of our PocketPC applications?
Next
column, I want to start exploring the CE Logo guidelines published by Microsoft.
I discovered a few places where my eVB applications needed work to bring them
in line and look forward to sharing this information with you.
Previous Page