Tuesday, 7 February 2017

simple whatsapp desktop interface in c#. it is working

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WhatsApp_Application;
using WhatsAppApi;
namespace WhatsApp_Application
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btn_send_Click(object sender, EventArgs e)
        {
            string from = "9199876543210"; //(Enter Your Mobile Number)
            string to = txt_to.Text;
            string msg = txt_msg.Text;
            WhatsApp wa = new WhatsApp(from, "WhatsAppPassword", "NickName", false, false);
            wa.OnConnectSuccess += () =>
            {
                MessageBox.Show("Connected to WhatsApp...");
                wa.OnLoginSuccess += (phonenumber, data) =>
                    {
                        wa.SendMessage(to, msg);
                        MessageBox.Show("Message Sent...");
                    };
                wa.OnLoginFailed += (data) =>
                    {
                        MessageBox.Show("Login Failed : {0} : ", data);
                    };

                wa.Login();
            };
            wa.OnConnectFailed += (Exception) =>
                {
                    MessageBox.Show("Connection Failed...");
                };          
        }
    }
}

No comments:

Post a Comment