or, you can allow the user to see and make any necessary adjustments to
your device's local date and time by presenting the user with a form that
contains two datetime pickers (one for the date, one for the time) and some
code
that looks like the code below. this saves you from having to branch out to
the system settings and hope the user returns to your app where you expect
him to.
--
Darren Shaffer
..NET Compact Framework MVP
Principal Architect
Connected Innovation
www.connectedinnovation.com
Imports System.Runtime.InteropServices
Public Class DateTimeCheck
Private _valueChanged As Boolean = False
Public Sub DateTimeCheck()
End Sub
<StructLayoutAttribute(LayoutKind.Sequential)> _
Private Structure SYSTEMTIME
Public year As Short
Public month As Short
Public dayOfWeek As Short
Public day As Short
Public hour As Short
Public minute As Short
Public second As Short
Public milliseconds As Short
End Structure
<DllImport("coredll.dll")> _
Private Shared Function SetLocalTime(ByRef time As SYSTEMTIME) As
Boolean
End Function
Private Sub dtpDeviceDate_ValueChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles dtpDeviceDate.ValueChanged
_valueChanged = True
End Sub
Private Sub dtpDeviceTime_ValueChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles dtpDeviceTime.ValueChanged
_valueChanged = True
End Sub
Private Sub DateTimeCheck_Closing(ByVal sender As System.Object, ByVal e
As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If _valueChanged Then
Dim st As SYSTEMTIME = New SYSTEMTIME()
st.month = dtpDeviceDate.Value.Month
st.day = dtpDeviceDate.Value.Day
st.year = dtpDeviceDate.Value.Year
st.hour = dtpDeviceTime.Value.Hour
st.minute = dtpDeviceTime.Value.Minute
Try
If SetLocalTime(st) Then
MessageBox.Show("Device Date and Time Successfully
Updated.", _
"Success", MessageBoxButtons.OK,
MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
Else
MessageBox.Show("Device Date and Time Update Failed. Go
to Start-->Settings-->System " & _
"and set your device date and time before continuing.",
_
"Update Failed", MessageBoxButtons.OK,
MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
End If
Catch ex As Exception
MessageBox.Show("Device Date and Time Update Failed. Go to
Start --> Settings --> System --> Clock & Alarms" & _
"and set your device's date and time before
continuing.", _
"Update Failed", MessageBoxButtons.OK,
MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
End Try
End If
End Sub
End Class