How to wait for web page fully loaded then open/create new form2 with webbrowser navigate to another page
I'm trying by checking using igetattribut on loaded site on form 1 but not working because checking is running before web fully loaded
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;
namespace bot
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
webbMain.Navigate("http://asia1.darkorbit.com/");
}
private void btnLogin_Click(object sender, EventArgs e)
{
var inputElements = webbMain.Document.GetElementsByTagName("input");
foreach (HtmlElement i in inputElements)
{
if (i.GetAttribute("name").Equals("username"))
{
i.InnerText = txtUsername.Text;
}
if (i.GetAttribute("name").Equals("password"))
{
i.Focus();
i.InnerText = txtPassword.Text;
}
}
var buttonElements = webbMain.Document.GetElementsByTagName("input");
foreach (HtmlElement b in inputElements)
{
if (b.GetAttribute("className").Equals("bgcdw_button bgcdw_login_form_login"))
{
b.InvokeMember("click");
}
}
}
}
}
what I'm trying to do is to change the text of the "last" lost focussed TxtBox by using a button. I know about the LostFocus method, but what are the actual paramaters that we have to give to that fuction?
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 System.Net;
using System.IO;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// this.ActiveControl = textBox2;
}
private Control _focusedControl;
private void button1_Click(object sender, EventArgs e)
{
SubmitData();
}
private void SubmitData()
{
if (_focusedControl != null)
{
_focusedControl.Text = "hi";
}
}
private void TextBox2_GotFocus(object sender, EventArgs e)
{
MessageBox.Show("Got focus.");
_focusedControl = (Control)sender;
}
}
}
So, what is happening is, no messagebox is popping and the _focusedCOntrol varable doesn't contain the last focus.
I'm trying to create program which display video from IP Camera.
This is my code :
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 Emgu.CV; //
using Emgu.CV.CvEnum; // usual Emgu Cv imports
using Emgu.CV.Structure; //
using Emgu.CV.UI;
using System.IO;
using System.Reflection;
using System.Windows;
using System.Runtime.InteropServices;
using Emgu.Util;
using System.Net;
namespace WindowsFormsApplication1
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
public Capture _capture;
public Mat imgOriginal;
private void imageBox2_Click(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
public void button1_Click(object sender, EventArgs e)
{
_capture = new Capture("http://192.168.1.148:8080/video");
_capture.ImageGrabbed += ProcessFrame;
_capture.Start();
}
public void ProcessFrame(object sender, EventArgs arg)
{
imgOriginal= _capture.QueryFrame();
ibOriginal.Image = imgOriginal;
}
}
}
It's getting stuck on this step (without expectation):
imgOriginal= _capture.QueryFrame();
Maybe i should you invoke method but i don't know how.
Im using Emgu 3.1.0 Link to Doc
I managed to troubleshoot this . I made some canonical and syntax mistakes.
I provide working code for community:
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 Emgu.CV; //
using Emgu.CV.CvEnum; // usual Emgu Cv imports
using Emgu.CV.Structure; //
using Emgu.CV.UI;
using System.IO;
using System.Reflection;
using System.Windows;
using System.Runtime.InteropServices;
using Emgu.Util;
using System.Net;
namespace WindowsFormsApplication1
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
Run();
}
public Capture _capture;
public Mat imgOriginal;
private void imageBox2_Click(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
void Run()
{
try
{
_capture = new Capture("http://192.168.1.148:8080/video");
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return;
}
Application.Idle += ProcessFrame;
}
void ProcessFrame(object sender, EventArgs e)
{
Mat frame = _capture.QueryFrame();
ibOriginal.Image = frame;
}
public void button1_Click(object sender, EventArgs e)
{
}
}
}
The web page is:
Google Tennis Results
What i'm trying to get as text is the tennis results in the top of the page.
Tried using webBrowser now but not getting it at all.
Not sure if it's also java script in the page or not but i can't parse it.
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 System.IO;
using System.Net;
using System.Threading;
using System.Runtime.InteropServices;
namespace Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
test1();
}
private void test1()
{
this.webBrowser1.ObjectForScripting = new MyScript();
}
[ComVisible(true)]
public class MyScript
{
public void CallServerSideCode()
{
var doc = ((Form1)Application.OpenForms[0]).webBrowser1.Document;
var renderedHtml = doc.GetElementsByTagName("HTML")[0].OuterHtml;
}
}
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("https://www.google.co.il/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=australian%20open%20atp");
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Navigate("javascript: window.external.CallServerSideCode();");
}
}
}
I have some problems to use the MSTSCLib to connect from 1 PC to another one.
It's working with Servers but not with normal Workstations...
private void btn_connect_Click(object sender, EventArgs e)
{
try
{
rdp_control.Server = tbx_servername.Text;
rdp_control.Connect();
tabPage1.Text = "Connected";
}
catch (Exception exp)
{
MessageBox.Show(exp.ToString());
}
}
private void btn_disconnect_Click(object sender, EventArgs e)
{
if (rdp_control.Connected.ToString() == "1")
{
rdp_control.Disconnect();
}
}
Both client and server applications are in the Same Network under the same NAT. Problem is the certificate,... I need to find a way to include the certificate. With the normal Remote Desktop from Windows, you see a MessageBox with the question:"Do you want to use this certificate.... blablabla" But this is not coming up with the RDP function in c#
Any Ideas?
Thanks B.R.
Following code shows a simple RDP client and server.
RDP Server
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 RDPCOMAPILib;
using AxMSTSCLib;
using System.Runtime.InteropServices;
namespace TCP_to_RDP_Converter
{
public partial class Form1 : Form
{
public static RDPSession currentSession = null;
public static void createSession()
{
currentSession = new RDPSession();
}
public static void Connect(RDPSession session)
{
session.OnAttendeeConnected += Incoming;
session.Open();
}
public static void Disconnect(RDPSession session)
{
session.Close();
}
public static string getConnectionString(RDPSession session, String authString,
string group, string password, int clientLimit)
{
IRDPSRAPIInvitation invitation =
session.Invitations.CreateInvitation
(authString, group, password, clientLimit);
return invitation.ConnectionString;
}
private static void Incoming(object Guest)
{
IRDPSRAPIAttendee MyGuest = (IRDPSRAPIAttendee)Guest;
MyGuest.ControlLevel = CTRL_LEVEL.CTRL_LEVEL_INTERACTIVE;
}
/// <summary>
/// Handle the form items
/// </summary>
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
createSession();
Connect(currentSession);
textConnectionString.Text = getConnectionString(currentSession,
"Test","Group","",5);
}
private void button2_Click(object sender, EventArgs e)
{
Disconnect(currentSession);
}
}
}
In order to use the RDP communication library you need to add rdpcompapi and Microsoft windows terminal services, form the COM references.
RDP Client
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 RDPCOMAPILib;
using AxRDPCOMAPILib;
namespace Simple_RDP_Client
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static void Connect(string invitation, AxRDPViewer display, string userName, string password)
{
display.Connect(invitation, userName, password);
}
public static void disconnect(AxRDPViewer display)
{
display.Disconnect();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
Connect(textConnectionString.Text, this.axRDPViewer, "", "");
}
catch (Exception)
{
MessageBox.Show("Unable to connect to the Server");
}
}
}
}
you can add reference to the AxRDPCOMAPILib by importing RDP viewer class component to the main form.
Full project can be downloaded from here [Download]:http://sandaruwmp.blogspot.com/2014/05/remote-desktop-application-with-rdp.html
use this....
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 MSTSCLib;
namespace RemoteTool
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MSTerminalServiceControl1.Server = textBox1.Text;
MSTerminalServiceControl1.UserName = textBox2.Text;
IMsTscNonScriptable secured = (IMsTscNonScriptable)MSTerminalServiceControl1.GetOcx();
secured.ClearTextPassword = textBox3.Text;
MSTerminalServiceControl1.Connect();
}
private void button2_Click(object sender, EventArgs e)
{
MSTerminalServiceControl1.Disconnect();
}
}
}