Imports System.Runtime.InteropServices
Public Class Form1
' Per documentation, Delegates in WinMobile must derive
' from EventHandler
Private sw As New EventHandler(AddressOf DelegateFunction)
' Constant - Instructs ShowWindow() to minimize
Private Const SW_MINIMIZED As Integer = 6
' Interop function call = Used to access the native
' function ShowWindow, which is used to minimize the form
_
Public Shared Function ShowWindow(ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As Boolean
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Create a new thread so that Form_Load can return
Dim minimizeThread As New System.Threading.Thread(AddressOf MinimizeFormAfterSleep)
' Execute the thread
minimizeThread.Start()
End Sub
Private Sub MinimizeFormAfterSleep()
' Pseudo-timer
System.Threading.Thread.Sleep(4000) ' Change 4000 (4 seconds) to a time more fitting to your needs
' Call the delegate that runs the minimize code
Me.Invoke(sw, Me, EventArgs.Empty)
End Sub
Private Sub DelegateFunction(ByVal sender As Object, ByVal e As EventArgs)
' Execute the minimize code
ShowWindow(Me.Handle, SW_MINIMIZED)
End Sub
End Class
|