Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        WebBrowser1.Navigate("http://vk.com/")
    End Sub
    ' Вход
    Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        If txtLogin.Text = Nothing And txtPass.Text = Nothing Then
            MsgBox("Заполните поля")
        Else
            WebBrowser1.Document.GetElementById("quick_email").InnerText = txtLogin.Text
            WebBrowser1.Document.GetElementById("quick_pass").InnerText = txtPass.Text
            WebBrowser1.Document.Forms(0).InvokeMember("submit")
            Try
                WebBrowser1.Navigate("http://vk.com/al_profile.php")
            Catch ex As Exception
                WebBrowser1.Navigate("http://vk.com/al_profile.php")
            End Try
        End If
    End Sub
    ' Выход 
    Private Sub btnQuit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnQuit.Click
        Dim allelements As HtmlElementCollection = WebBrowser1.Document.All
        For Each webpageelement As HtmlElement In allelements
            If webpageelement.InnerText = "выйти" Then
                webpageelement.InvokeMember("click")
            End If
        Next
    End Sub
    ' Новая запись на стене
    Private Sub btnPost_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnPost.Click
        If txtMessage.Text = Nothing Then
            MsgBox("Поле не может быть пустым")
        Else
            Try
                WebBrowser1.Document.GetElementById("post_field").InnerText = txtMessage.Text
                Dim allelements As HtmlElementCollection = WebBrowser1.Document.All
                For Each webpageelement As HtmlElement In allelements
                    If webpageelement.InnerText = "Отправить" Then
                        webpageelement.InvokeMember("click")
                    End If
                Next
            Catch ex As Exception
                WebBrowser1.Document.GetElementById("ba_text").InnerText = txtMessage.Text
                Dim allelements1 As HtmlElementCollection = WebBrowser1.Document.All
                For Each webpageelement1 As HtmlElement In allelements1
                    If webpageelement1.InnerText = "Отправить" Then
                        webpageelement1.InvokeMember("click")
                    End If
                Next
            End Try
        End If
    End Sub
    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        Me.Text = WebBrowser1.Document.Title
    End Sub
    Private Sub btnSendDialog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndialog.Click
        Try
            WebBrowser1.Navigate("http://vk.com/im?sel=" & txtId.Text)
            btnsenddialog.Enabled = True
        Catch ex As Exception
            WebBrowser1.Navigate("http://vk.com/im?sel=" & txtId.Text)
            btnsenddialog.Enabled = True
        End Try
    End Sub

    Private Sub btnsenddialog_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsenddialog.Click
        If txtMesageDialog.Text = Nothing And txtId.Text = Nothing Then
            MsgBox("Поле не может быть пустым")
        Else
            Try
                WebBrowser1.Document.GetElementById("im_editable" & txtId.Text).InnerText = txtMesageDialog.Text
                Dim allelements As HtmlElementCollection = WebBrowser1.Document.All
                For Each webpageelement As HtmlElement In allelements
                    If webpageelement.InnerText = "Отправить" Then
                        webpageelement.InvokeMember("click")
                    End If
                Next
            Catch ex As Exception
                WebBrowser1.Document.GetElementById("im_editable" & txtId.Text).InnerText = txtMesageDialog.Text
                Dim allelements As HtmlElementCollection = WebBrowser1.Document.All
                For Each webpageelement As HtmlElement In allelements
                    If webpageelement.InnerText = "Отправить" Then
                        webpageelement.InvokeMember("click")
                    End If
                Next
            End Try
        End If
    End Sub
End Class
