Windows Forms: Sending WhatsApp Message using C#
By FoxLearn 7/12/2017 9:04:04 PM 22.23K
How to send WhatsApp Message using C# Code
Step 1: Click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "SmsWhatsApp" and then click OK
Step 2: Download WhatsApp API. This is an API written in C# but it can be used in any .NET language. It's a fork from WhatsAPINet, which is based on Chat API
Step 3: Design your form as below
Step 4: Add code to handle your form
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using WhatsAppApi; namespace SmsWhatsApp { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnSend_Click(object sender, EventArgs e) { WhatsApp wa = new WhatsApp(txtPhone.Text, txtPassword.Text, txtName.Text, true); //Open connect wa.OnConnectSuccess += () => { txtStatus.Text = "Connected..."; byte[] img = File.ReadAllBytes("e:\\250.gif"); //Login wa.OnLoginSuccess += (phone, data) => { txtStatus.Text += "\r\nLogin success !"; //wa.SendMessage(txtTo.Text, txtMessage.Text); //Send whatsapp message with image file wa.SendMessageImage(txtTo.Text, img, ApiBase.ImageType.GIF); txtStatus.Text += "\r\nMessage sent !"; }; wa.OnLoginFailed += (data) => { txtStatus.Text += string.Format("\r\nLogin failed {0}", data); }; wa.Login(); }; wa.OnConnectFailed += (ex) => { txtStatus.Text += string.Format("\r\nConnect failed {0}", ex.StackTrace); }; wa.Connect(); } } }
VIDEO TUTORIALS
- Windows Forms: Advanced Filter DataGridView in C#
- Windows Forms: Progress Bar in C#
- How to create a Lucky Draw games in C#
- Windows Forms: Youtube Search with Paging in C#
- Windows Forms: How to Create a Random Password Generator in C#
- Windows Forms: Tag Control in C#
- Windows Forms: Wait Form Dialog in C#
- Windows Forms: Text to speech in C#