Windows Forms: Sending WhatsApp Message using C#
By Tan Lee Published on Jul 12, 2017 23.62K
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
- How to Open and Show a PDF file in C#
- How to Get all Forms and Open Form with Form Name in C#
- How to zoom an image in C#
- How to Print a Picture Box in C#
- How to update UI from another thread in C#
- How to Search DataGridView by using TextBox in C#
- How to read and write to text file in C#
- How to save files using SaveFileDialog in C#
Categories
Popular Posts
11 Things You Didn't Know About Cloudflare
Dec 19, 2024
Gentella Admin Template
Nov 14, 2024
Login SignUp form using HTML CSS JS
Nov 11, 2024
Freedash bootstrap lite
Nov 13, 2024