I attempted to open a Windows form using the DotNetBrowser control with specific HTML content as shown in the code below.
Upon clicking a button on the HTML page, I want to hide the loaded form and then display the second Windows form.
Here is the C# code that I used:
public partial class Form1 : Form
{
private Browser browser;
public Form1()
{
InitializeComponent();
browser = BrowserFactory.Create();
browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e)
{
if (e.IsMainFrame)
{
JSValue value = browser.ExecuteJavaScriptAndReturnValue("window");
value.AsObject().SetProperty("Account", new Form1());
}
};
browser.LoadHTML(@"<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
function sendFormData() {
var firstNameValue = myForm.elements['firstName'].value;
var lastNameValue = myForm.elements['lastName'].value;
// Invoke the 'save' method of the 'Account' Java object.
Account.Save(firstNameValue, lastNameValue);
}
</script>
</head>
<body>
<form name='myForm'>
First name: <input type='text' name='firstName'/>
<br/>
Last name: <input type='text' name='lastName'/>
<br/>
<input type='button' value='Save' onclick='sendFormData();'/>
</form>
</body>
</html>");
BrowserView browserView = new WinFormsBrowserView(browser);
this.Controls.Add((Control)browserView.GetComponent());
}
public void Save(String firstName, String lastName)
{
string _firstname = firstName;
this.Hide();
SecondForm frm = new SecondForm(firstName);
frm.ShowDialog();
}
The issue I am facing is that the first form containing the browser control does not hide and remains focused.
Your assistance in resolving this matter would be greatly appreciated.