Imports System.Drawing

Public Class usrCntlMessenger_ChatElement
    Property CHAT_MSG As VERAG_PROG_ALLGEMEIN.cMessenger.cMessenger_ChatMessages
    'Property BG_COLOR As Color = Color.FromArgb(192, 255, 192) ' Color.Azure
    Dim ttp As New System.Windows.Forms.ToolTip

    Sub New()

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.

    End Sub

    Sub New(CHAT_MSG As VERAG_PROG_ALLGEMEIN.cMessenger.cMessenger_ChatMessages)

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()
        Me.CHAT_MSG = CHAT_MSG
        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.

    End Sub
    Sub setBgCOLOR(BG_COLOR)
        ' Me.BG_COLOR = BG_COLOR
        txtChatmessage.BackColor = BG_COLOR
        Panel1.BackColor = BG_COLOR
    End Sub

    Private Sub usrCntlMessenger_ChatElement_Load(sender As Object, e As EventArgs) Handles Me.Load
        ttp.SetToolTip(lblDel, "Element innerhalb 60 Sek. löschen")
        ' setBgCOLOR(Color.Azure)
        If CHAT_MSG IsNot Nothing Then
            If CHAT_MSG.chatMg_type.Contains("DEL_") Then
                txtChatmessage.Text = "*gelöscht"
            Else

                lblDateTime.Text = CHAT_MSG.chatMg_datetime.ToString("dd.MM.yyyy HH:mm:ss")
                lblName.Text = CHAT_MSG.chatMg_maName & " (" & CHAT_MSG.chatMg_maFirma & ")"
                txtChatmessage.Text = CHAT_MSG.chatMg_text
                Dim cnt = 0
                While (txtChatmessage.Size.Width - txtChatmessage.ClientSize.Width > 10) And cnt < 20 ' (txtChatmessage.Height - txtChatmessage.ClientSize.Height) > MyRTBInnerSize Or cnt > 100
                    Me.Height += 20 : cnt += 1
                End While
                setRead()

                If CHAT_MSG.chatMg_maId = VERAG_PROG_ALLGEMEIN.cAllgemein.USRID Then
                    If CHAT_MSG.chatMg_datetime > Now.AddSeconds(-60) Then
                        lblDel.Visible = True
                        Timer1.Enabled = True
                    End If
                End If

            End If
        End If

    End Sub

    Sub setRead()
        For Each ST In CHAT_MSG.CHAT_MESSAGES_STATUS_LIST
            If ST.chatMgSt_MaId = VERAG_PROG_ALLGEMEIN.cAllgemein.USRID Then
                lblNewMsg.Visible = Not ST.chatMgSt_gelesen
            End If
        Next
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        If CHAT_MSG IsNot Nothing Then
            If CHAT_MSG.chatMg_maId = VERAG_PROG_ALLGEMEIN.cAllgemein.USRID Then
                If CHAT_MSG.chatMg_datetime > Now.AddSeconds(-60) Then
                    lblDel.Visible = True
                Else
                    lblDel.Visible = False
                    Timer1.Enabled = False
                End If
            End If
        End If
    End Sub

    Private Sub lblDel_Click(sender As Object, e As EventArgs) Handles lblDel.Click
        CHAT_MSG.DELETE_MESSAGE()
        usrCntlMessenger_ChatElement_Load(Me, New EventArgs)
        lblDel.Visible = False
    End Sub
End Class
