'****************************************************************************************
' File: myMsgBox.vb                          
' Programmer: John Elliott
' Date: January 28, 2002
'
' Description:
' Form to display a "no-wait" message box.
'
' Form to display a message box similar to the way the VB MsgBox()
' function does it.  But it does not stop event processing while waiting
' for user input like the way the VB MsgBox() does.
'
' Useful for showing warning and error messages without holding up execution
' flow.
'
' Including a message showing the number of unread new messages.
'
' Usage:
'    Put title of message in MyMsgBoxForm.Caption.
'    Put body of message in MyMsgBoxForm.Label1.Caption.
'
' Modification History:
' 2005-05-30 Revised by Ting Chan, UWEE
' 2005-05-30 Added Message Counter to show the number of new 
'            message by Ting Chan, UWEE
' 2005-05-31 Added the first event flags to show whether the 
'            message is new by Ting Chan, UWEE
'
'***************************************************************************************
Option Strict Off
Option Explicit On 
Friend Class MyMsgBoxForm
    Inherits System.Windows.Forms.Form
#Region "Windows Form Designer generated code "
    Public Sub New()
        MyBase.New()
        If m_vb6FormDefInstance Is Nothing Then
            If m_InitializingDefInstance Then
                m_vb6FormDefInstance = Me
            Else
                Try
                    'For the start-up form, the first instance created is the default instance.
                    If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Then
                        m_vb6FormDefInstance = Me
                    End If
                Catch
                End Try
            End If
        End If
        'This call is required by the Windows Form Designer.
        InitializeComponent()
        Me.MdiParent = Project1.PMACSstartup.DefInstance.DefInstance
        Project1.PMACSstartup.DefInstance.DefInstance.Show()
    End Sub
    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
        If Disposing Then
            If Not components Is Nothing Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(Disposing)
    End Sub
    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer
    Public ToolTip1 As System.Windows.Forms.ToolTip
    Public WithEvents CommandOk As System.Windows.Forms.Button
    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.
    'Do not modify it using the code editor.
    Friend WithEvents Label1 As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents CheckBoxAutoBottom As System.Windows.Forms.CheckBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.CommandOk = New System.Windows.Forms.Button
        Me.Label1 = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.CheckBoxAutoBottom = New System.Windows.Forms.CheckBox
        Me.SuspendLayout()
        '
        'CommandOk
        '
        Me.CommandOk.BackColor = System.Drawing.SystemColors.Control
        Me.CommandOk.Cursor = System.Windows.Forms.Cursors.Default
        Me.CommandOk.Font = New System.Drawing.Font("Arial", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.CommandOk.ForeColor = System.Drawing.SystemColors.ControlText
        Me.CommandOk.Location = New System.Drawing.Point(240, 272)
        Me.CommandOk.Name = "CommandOk"
        Me.CommandOk.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.CommandOk.Size = New System.Drawing.Size(81, 25)
        Me.CommandOk.TabIndex = 0
        Me.CommandOk.Text = "OK"
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.Color.White
        Me.Label1.Font = New System.Drawing.Font("Arial", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(32, 40)
        Me.Label1.Multiline = True
        Me.Label1.Name = "Label1"
        Me.Label1.ReadOnly = True
        Me.Label1.ScrollBars = System.Windows.Forms.ScrollBars.Both
        Me.Label1.Size = New System.Drawing.Size(496, 224)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = ""
        Me.Label1.WordWrap = False
        '
        'Label2
        '
        Me.Label2.BackColor = System.Drawing.Color.Black
        Me.Label2.Font = New System.Drawing.Font("Arial", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.ForeColor = System.Drawing.Color.Lime
        Me.Label2.Location = New System.Drawing.Point(88, 8)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(384, 24)
        Me.Label2.TabIndex = 2
        Me.Label2.Text = "shows how many new messages you have"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'CheckBoxAutoBottom
        '
        Me.CheckBoxAutoBottom.BackColor = System.Drawing.SystemColors.Control
        Me.CheckBoxAutoBottom.Font = New System.Drawing.Font("Arial", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.CheckBoxAutoBottom.Location = New System.Drawing.Point(368, 272)
        Me.CheckBoxAutoBottom.Name = "CheckBoxAutoBottom"
        Me.CheckBoxAutoBottom.Size = New System.Drawing.Size(144, 24)
        Me.CheckBoxAutoBottom.TabIndex = 30
        Me.CheckBoxAutoBottom.Text = "Scroll to Bottom"
        '
        'MyMsgBoxForm
        '
        Me.AutoScale = False
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.SystemColors.Control
        Me.ClientSize = New System.Drawing.Size(554, 308)
        Me.Controls.Add(Me.CheckBoxAutoBottom)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.CommandOk)
        Me.Cursor = System.Windows.Forms.Cursors.Default
        Me.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Location = New System.Drawing.Point(4, 23)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "MyMsgBoxForm"
        Me.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Text = "MyMsgBox Title "
        Me.ResumeLayout(False)

    End Sub
#End Region
#Region "Upgrade Support "
    Private Shared m_vb6FormDefInstance As MyMsgBoxForm
    Private Shared m_InitializingDefInstance As Boolean
    Public Shared Property DefInstance() As MyMsgBoxForm
        Get
            If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
                m_InitializingDefInstance = True
                m_vb6FormDefInstance = New MyMsgBoxForm
                m_InitializingDefInstance = False
            End If
            DefInstance = m_vb6FormDefInstance
        End Get
        Set(ByVal Value As MyMsgBoxForm)
            m_vb6FormDefInstance = Value
        End Set
    End Property
#End Region

#Region "Click OK button"
    '***********************************************************************
    ' if the user clicks the OK button, assume all messages have been read
    ' and close the message box window.
    ' The Message box would now be set as an empty box.
    '***********************************************************************
    Private Sub CommandOk_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandOk.Click

        'close the message box window
        MyMsgBoxForm.DefInstance.Close()

        'reset the message counter
        MessageCount = 0

        'reset all the first event flag
        FirstEventFlagNPC = True
        FirstEventFlagNPCState = True
        FirstEventFlagExtLoad = True
        FirstEventFlagIntLoad = True
        FirstEventFlagBus = True
        FirstEventFlagSensor = True
        FirstEventFlagMV = True
        FirstEventFlagShore = True
        FirstEventFlagGF400 = True
        FirstEventFlagGF48 = True
        FirstEventFlagGFCom = True
        FirstEventFlagGFUnknown = True
        FirstEventFlagGF = True
    End Sub
#End Region

#Region "User press a key when the OK button is highlighted"
    Private Sub CommandOk_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles CommandOk.KeyPress
        Dim KeyAscii As Short = Asc(eventArgs.KeyChar)

        'If the User press Enter or Esc, the message box window
        'will be closed
        If KeyAscii = 27 Or KeyAscii = Asc(vbCr) Then
            'jbe: User pressed escape key or return.
            MyMsgBoxForm.DefInstance.Close()
            MessageCount = 0
        End If

        ' if the user press any key other than Enter or Esc
        ' The message box will remain open, but will reset
        ' all the first event flag, so new message (Including
        ' repeated) will show up on the same message box window
        If KeyAscii = 0 Then
            eventArgs.Handled = True
        End If

        'MessageCount = 0
        FirstEventFlagNPC = True
        FirstEventFlagNPCState = True
        FirstEventFlagExtLoad = True
        FirstEventFlagIntLoad = True
        FirstEventFlagBus = True
        FirstEventFlagSensor = True
        FirstEventFlagMV = True
        FirstEventFlagShore = True
        FirstEventFlagGF400 = True
        FirstEventFlagGF48 = True
        FirstEventFlagGFCom = True
        FirstEventFlagGFUnknown = True
        FirstEventFlagGF = True
    End Sub
#End Region

#Region "Check scroll to bottom check box"
    Private Sub CheckBoxAutoBottom_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxAutoBottom.CheckedChanged
        ' if the CheckBoxAutoBottom check box is checked
        ' set a flag to have the textbox scroll to bottom
        If CheckBoxAutoBottom.Checked = True Then
            MessageBottom = True
        Else
            MessageBottom = False
        End If
    End Sub
#End Region

#Region "Close the message box window"
    '**************************************************************************
    ' User decides to close the message box window, reset all the first event 
    ' flags and the message counter
    '**************************************************************************
    Private Sub MyMsgBoxForm_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        MessageCount = 0
        FirstEventFlagNPC = True
        FirstEventFlagNPCState = True
        FirstEventFlagExtLoad = True
        FirstEventFlagIntLoad = True
        FirstEventFlagBus = True
        FirstEventFlagSensor = True
        FirstEventFlagMV = True
        FirstEventFlagShore = True
        FirstEventFlagGF400 = True
        FirstEventFlagGF48 = True
        FirstEventFlagGFCom = True
        FirstEventFlagGFUnknown = True
        FirstEventFlagGF = True
    End Sub
#End Region

End Class