Imports vbicq4
Public Class Form1
    Public WithEvents ICQ As New vbicq4.vbicq4
    Delegate Sub ErrDelegate(ByVal d As String) 
    Delegate Sub MsgDelegate(ByVal u As String, ByVal m As String)
    Delegate Sub OnConDelegate()
    ' Подключение
    Private Sub Coonect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Coonect.Click
        ICQ.UIN = UIN.Text
        ICQ.pass = Pass.Text
        ICQ.connect()
        Timer1.Start()
    End Sub
    ' Зашли
    Private Sub ICQ_onConnect() Handles ICQ.onConnect
        If InvokeRequired Then
            Me.BeginInvoke(New OnConDelegate(AddressOf icq_onConnect))
            Exit Sub
        End If
        Label3.Text = "Статус : В сети"
        Coonect.Enabled = False
        ComboBox1.SelectedIndex = 0
        If IO.File.Exists(IO.Directory.GetCurrentDirectory & "/Auth.wav") Then
            My.Computer.Audio.Play(IO.Directory.GetCurrentDirectory & "/Auth.wav")
        End If
    End Sub
    ' Вышли
    Private Sub ICQ_onDisconnect() Handles ICQ.onDisconnect
        If InvokeRequired Then
            Me.BeginInvoke(New OnConDelegate(AddressOf icq_onDisconnect))
            Exit Sub
        End If
        Label3.Text = "Статус : Отключен"
        Coonect.Enabled = True
    End Sub
    ' Ошибка
    Private Sub ICQ_onError(ByVal Description As String) Handles ICQ.onError
        If InvokeRequired Then
            Me.BeginInvoke(New ErrDelegate(AddressOf icq_onError), Description)
            Exit Sub
        End If
        Label3.Text = "Статус : Ошибка - " & Description
        Coonect.Enabled = True
    End Sub
    ' Принятие сообщений
    Private Sub icq_onMessage(ByVal uin As String, _
                              ByVal message As String) Handles ICQ.onMessage
        If InvokeRequired Then
            Me.BeginInvoke(New MsgDelegate(AddressOf icq_onMessage), _
                           New Object() {uin, message})
            Exit Sub
        End If
        If IO.File.Exists(IO.Directory.GetCurrentDirectory & "/PrinSms.wav") Then
            My.Computer.Audio.Play(IO.Directory.GetCurrentDirectory & "/PrinSms.wav")
        End If
        ListBox1.Items.Add("Вам написал - > " & uin & " : " & message)
    End Sub
    ' Отправка сообщений
    Private Sub Send_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Send.Click
        If ICQ.KeepAlive Then
            ICQ.SendMessage(UINSend.Text, TextSend.Text)
            ListBox1.Items.Add("Я написал - > " & UINSend.Text & " : " & TextSend.Text)
            If IO.File.Exists(IO.Directory.GetCurrentDirectory & "/SendSms.wav") Then
                My.Computer.Audio.Play(IO.Directory.GetCurrentDirectory & "/SendSms.wav")
            End If
            TextSend.Text = ""
        Else
            MsgBox("Вы не подключены к сети")
        End If
    End Sub
    ' Отключаемся
    Private Sub DisConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DisConnect.Click
        ICQ.DisConnect()
        Coonect.Enabled = True
        ComboBox1.SelectedIndex = 12
    End Sub
    ' Следим за статусом
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label3.Text = "Статус : " & ICQ.state
    End Sub
    Private Sub PassChar_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PassChar.CheckedChanged
        If PassChar.Checked = True Then
            Pass.PasswordChar = ""
        Else
            Pass.PasswordChar = "*"
        End If
    End Sub
    ' Статус
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Select Case ComboBox1.SelectedIndex
            Case 0
                ICQ.SetStatus(vbicq4.vbicq4.ICQ_Status.online)
            Case 1
                ICQ.SetStatus(vbicq4.vbicq4.ICQ_Status.offline)
            Case 2
                ICQ.SetStatus(vbicq4.vbicq4.ICQ_Status.cruel)
            Case 3
                ICQ.SetStatus(vbicq4.vbicq4.ICQ_Status.away)
            Case 4
                ICQ.SetStatus(vbicq4.vbicq4.ICQ_Status.depr)
            Case 5
                ICQ.SetStatus(vbicq4.vbicq4.ICQ_Status.NA)
            Case 6
                ICQ.SetStatus(vbicq4.vbicq4.ICQ_Status.Occupied)
            Case 7
                ICQ.SetStatus(vbicq4.vbicq4.ICQ_Status.DND)
            Case 8
                ICQ.SetStatus(vbicq4.vbicq4.ICQ_Status.working)
            Case 9
                ICQ.SetStatus(vbicq4.vbicq4.ICQ_Status.home)
            Case 10
                ICQ.SetStatus(vbicq4.vbicq4.ICQ_Status.eat)
            Case 11
                ICQ.SetStatus(vbicq4.vbicq4.ICQ_Status.invisible)
            Case 12
                ICQ.SetStatus(vbicq4.vbicq4.ICQ_Status.unknow)
        End Select
    End Sub
    Private Sub TextSend_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextSend.KeyDown
        If e.KeyCode = Keys.Enter Then
            Send.PerformClick()
        End If
    End Sub
End Class
