C# Chromium browser whatsapp web send message using textbox - c#

I already follow the Chromium user guide, still doesn't work. Using my C# program, I want to send message or image via whatsapp web by cascading the textbox in my program with the message box of whatsapp. This is my code
using CefSharp;
using CefSharp.WinForms;
using System;
using System.Windows.Forms;
namespace ChromiumwithEditorWsWeb
{
public partial class Form1 : Form
{
ChromiumWebBrowser browser;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
CefSettings settings = new CefSettings();
Cef.Initialize(settings);
browser = new ChromiumWebBrowser("http://web.whatsapp.com");
browser.Dock = DockStyle.Fill;
panel1.Controls.Add(browser);
}
private void buttonBack_Click(object sender, EventArgs e)
{
browser.Back();
}
private void buttonForward_Click(object sender, EventArgs e)
{
browser.Forward();
}
private void buttonReload_Click(object sender, EventArgs e)
{
browser.ShowDevTools();
}
private void buttonGo_Click(object sender, EventArgs e)
{
browser.Load(textBoxUrl.Text);
}
private void buttonPhoneNo_Click(object sender, EventArgs e)
{
browser.EvaluateScriptAsync("document.GetElementsByClass('jN-F5 copyable-text selectable-text').value = textBoxPhone.Text");
browser.EvaluateScriptAsync("document.GetElementsByClass('_2S1VP copyable-text selectable-text').value = textBoxMessage.Text");
}
}
}
Help it! Give suggestions for the best step.

Clipboard.SetText(msg);
Thread.Sleep(TimeSpan.FromSeconds(2));
SendKeys.Send(msg); //SendKeys.SendWait("^{V}");
Thread.Sleep(TimeSpan.FromSeconds(1));
SendKeys.SendWait("{ENTER}");
Not a good solution though, as it requires the windows to be on focus and this uses the clipboard. But it works !

Related

CefSharp Set Object reference for buttons C#?

WinForms:
I am new to Cefsharp and C# , just wrote a freeware 'Kid Safe Browser' in VS vb.net in visual basic , but IE11 is too limited .
I am getting "Object reference not set" for all Buttons . How to fix this ? For example:
How do I set an Object Reference for Chrome Load and Navigate Back Forward Refresh etc. ?
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=CefSharpBrowser01
StackTrace:
at CefSharpBrowser01.SafeBrowser.GotoBtn_Click(Object sender, EventArgs e) in
C:\Users\vmars\source\repos\CefSharpBrowser01\Form1.cs:line 64
using CefSharp.WinForms;
using CefSharp.WinForms.Internals;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp;
using cef;
namespace CefSharpBrowser01
{
public partial class SafeBrowser : Form
{
public SafeBrowser()
{
InitializeComponent();
}
ChromiumWebBrowser chrome;
private void SafeBrowser_Load(object sender, EventArgs e)
{
CefSettings settings = new CefSettings();
//Initialize;
Cef.Initialize(settings);
AddressTxt.Text = "https://www.google.com";
chrome = new ChromiumWebBrowser(AddressTxt.Text);
this.Controls.Add(chrome);
chrome.Dock = DockStyle.Fill;
chrome.AddressChanged += Chrome_AddressChanged;
}
private void Chrome_AddressChanged(object sender, AddressChangedEventArgs e)
{
this.Invoke(new MethodInvoker(() =>
{
AddressTxt.Text = e.Address;
}));
}
private void BackBtn_Click(object sender, EventArgs e)
{
if (chrome.CanGoBack)
chrome.Back();
}
private void ForwardBtn_Click(object sender, EventArgs e)
{
if (chrome.CanGoForward)
chrome.Forward();
}
private void RefreshBtn_Click(object sender, EventArgs e)
{
chrome.Refresh();
}
private void GotoBtn_Click(object sender, EventArgs e)
{
chrome.Load(AddressTxt.Text);
}
}
}
Thanks for your Help...
Your problem really isn't anything to do with CefSharp, it's that you haven't created an instance of a class that you are trying to reference. Refactoring your code like I've suggested in the comments so the class is actually instantiated.
namespace CefSharpBrowser01
{
public partial class SafeBrowser : Form
{
public SafeBrowser()
{
InitializeComponent();
CefSettings settings = new CefSettings();
//Initialize;
Cef.Initialize(settings);
AddressTxt.Text = "https://www.google.com";
chrome = new ChromiumWebBrowser(AddressTxt.Text);
this.Controls.Add(chrome);
chrome.Dock = DockStyle.Fill;
chrome.AddressChanged += Chrome_AddressChanged;
}
ChromiumWebBrowser chrome;
private void Chrome_AddressChanged(object sender, AddressChangedEventArgs e)
{
this.Invoke(new MethodInvoker(() =>
{
AddressTxt.Text = e.Address;
}));
}
private void BackBtn_Click(object sender, EventArgs e)
{
if (chrome.CanGoBack)
chrome.Back();
}
private void ForwardBtn_Click(object sender, EventArgs e)
{
if (chrome.CanGoForward)
chrome.Forward();
}
private void RefreshBtn_Click(object sender, EventArgs e)
{
chrome.Refresh();
}
private void GotoBtn_Click(object sender, EventArgs e)
{
chrome.Load(AddressTxt.Text);
}
}
}

C# Winforms change label based on running process

I have a dotnet 2.0 app in C# that I have developed in Visual Studio 2008, it's pretty simple:
I would like to change the label name currently called "label1" to "Running" or "Stopped" when my process loop.exe is running or stopped.
When I press start, it will run loop.exe and the stop button will obviously stop it.
I've read a lot of topic on C# Winforms but I cannot get this working and I have no idea what do to now. I think that I need to add a backgroundworker but I don't know how to check the process and update the label programmatically.
Here's my clean/current code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace APP_NAME
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Start_Click(object sender, EventArgs e)
{
Process.Start("loop.exe");
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Process.Start("taskkill", "/F /IM loop.exe");
Process.Start("taskkill", "/F /IM azcopy.exe");
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button3_Click(object sender, EventArgs e)
{
Process.Start("notepad.exe", #"C:\ProgramData\APP_NAME\settings\settings.xml");
}
private void button4_Click(object sender, EventArgs e)
{
Process.Start("explorer.exe", #"C:\ProgramData\APP_NAME\logs");
}
}
}
I hope I made myself clear, thank you.
You can update the text shown by a label by accessing it's Text property. So, change your method like:
private void Start_Click(object sender, EventArgs e)
{
Process.Start("loop.exe");
label1.Text = "Running";
}
//hi
//Do this to see the label value changes in real time in the window
private void Start_Click(object sender, EventArgs e)
{
Process.Start("loop.exe");
label1.Text = "Running";
lable1.Refresh();
}

Windows Form is Really Laggy

I have a windows Form Project that runs smoothly and fine on framework 4.5.1
But yet I have a project on framework 2.0 that is so laggy even after i changed the target framework to 4.5.1
so why is one project slow and the other is normal?
Update :
here is the Main From
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DataBaseLab_Library_Project
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void button5_Click(object sender, EventArgs e)
{
System.Windows.Forms.Application.Exit();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
MessageBox.Show(" ", "About US");
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
Add AddForm = new Add();
AddForm.Show();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
Search SearchForm = new Search();
SearchForm.Show();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
}
}
and here is its design
Update 2 :
Form "Add.cs" that dose not lag .
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DataBaseLab_Library_Project
{
public partial class Add : Form
{
public Add()
{
InitializeComponent();
}
private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
AddBook AddBookForm = new AddBook();
AddBookForm.Show();
}
private void button4_Click(object sender, EventArgs e)
{
this.Close();
MainForm mainForm = new MainForm();
mainForm.Show();
}
private void label3_Click(object sender, EventArgs e)
{
}
private void publisherButt_Click(object sender, EventArgs e)
{
this.Close();
AddPublishercs AddPublisherForm = new AddPublishercs();
AddPublisherForm.Show();
}
private void authorButt_Click(object sender, EventArgs e)
{
//this.Close();
//AddAuthor AddAuthorForm = new AddAuthor();
//AddAuthorForm.Show();
}
private void Add_Load(object sender, EventArgs e)
{
}
}
}
Try removing the panel1 paint eventhandler. This will get called (even tho its empty) ever time the panel has to draw itself, which is all the time in a designer environment.
Remove this code:
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
There will also be code inside of InitializeComponent() similar to this
this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1);
Remove it as well. Clean and rebuild solution. Close all designer windows. Try again.

Screen sharing Application in C# for Windows Xp with using RDP Viewer Class Component

I am trying to develop Basic Screen Sharing Application for in C# language for windows Xp.
I have develop Basic Application with using RDPCOMAPILib means rdpcomapi 1.0 type library
and RDPViewer Class Component. its works fine on windows 7 but its not work on windows XP because its not find RDPViewer Class Component I have created two module for this first for host and Second is Viewer In host its generate unique code which use for connect to remote computer. My code is below
using System.Runtime.InteropServices;
using RDPCOMAPILib;
RDPSession x = new RDPSession();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Incoming(object Guest)
{
IRDPSRAPIAttendee MyGuest = (IRDPSRAPIAttendee)Guest;//???
MyGuest.ControlLevel = CTRL_LEVEL.CTRL_LEVEL_INTERACTIVE;
}
private void button1_Click(object sender, EventArgs e)
{
x.OnAttendeeConnected += Incoming;
x.Open();
}
private void button2_Click(object sender, EventArgs e)
{
IRDPSRAPIInvitation Invitation = x.Invitations.CreateInvitation("Trial", "MyGroup", "", 10);
textBox1.Text = Invitation.ConnectionString;
}
private void button3_Click(object sender, EventArgs e)
{
x.Close();
x = null;
}
And Viewer Code is
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string Invitation = textBox1.Text;// "";// Interaction.InputBox("Insert Invitation ConnectionString", "Attention");
axRDPViewer1.Connect(Invitation, "User1", "");
}
private void button2_Click(object sender, EventArgs e)
{
axRDPViewer1.Disconnect();
}
private void Form1_Load(object sender, EventArgs e)
{
panel1.Height = Screen.PrimaryScreen.Bounds.Height - 100;
}
}
According to the MSDN articles for IRDPSRAPIAttendee and IRDPSRAPIInvitation, the APIs that you are trying to use are only available on Windows Vista and later. Thus, I don't think you'll be able them on Windows XP.

Can't write into a RichTextBox control

I can't write in richTextBox or the textBox , whenever I start to write something it freezes my program. Any idea what it is ? I haven't changed anything in code or properties of the textBox.
using System.Text;
using System.Windows.Forms;
using System.IO;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
File.WriteAllText("TextFile1.txt", richTextBox1.Text);
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
richTextBox1.LoadFile ("TextFile1.txt");
}
}
It looks like you are loading a file into the text box that you are writing in:
So get rid of this piece of code:
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
richTextBox1.LoadFile ("TextFile1.txt");
}
Try moving it into the OnLoad method of the form (assuming you want the text box populated when the form opens):
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
richTextBox1.LoadFile ("TextFile1.txt");
}
The RichTextBox also has a SaveFile method. It's not clear from your code if the "rich" text is important to the application.
bool _isLoading = false;
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
if(_isLoading) return;
_isLoading = true;
richTextBox1.LoadFile ("TextFile1.txt");
_isLoading = false;
}

Categories