|
Rank: Member Groups: Member
Joined: 2/8/2023 Posts: 14
|
Hi, I am evaluating the product EO WebBrowser control to replace IE WebBrowser control. I want to use EO WebBrowser control in Winforms in C#. We have a web application where specific information related to popup and other windows are part of the application (Javascript code), for example; opening location, size etc. and each popup window is having some button to perform some action and close the window. If I have to use EO WebBrowser control then what should be approach for the same, if you could share a sample application that would be great. Or please guide me how to handle the below scenarios/issues: 1. Do not want to specify the size/location to the form explicitly while opening a popup window, it should take implicitly from the application/page where JS has already providing it in window.open. 2. Clicking on the page button "Close" window.close is closing the EO WebBrowser, but not the form itself. The code I tried in a sample application is as follows:
Code: C#
public partial class Browser : Form
{
protected string Url;
public string UserName { get; set; }
public string Password { get; set; }
public Browser(string url, string userName, string password)
{
this.Url = url;
this.UserName = userName;
this.Password = password;
InitializeComponent();
webControl1.WebView = new EO.WebBrowser.WebView();
//webControl1.WebView.NeedCredentials += WebView_NeedCredentials;
webControl1.WebView.NewWindow += WebView_NewWindow;
webControl1.WebView.Url = this.Url;
}
#region Events
private void WebView_NeedCredentials(object sender, EO.WebBrowser.NeedCredentialsEventArgs e)
{
e.Continue(this.UserName, this.Password);
}
private void WebView_NewWindow(object sender, NewWindowEventArgs e)
{
//Step 1:
//Create a new Form with a blank WebControl
//This new Form is the popup window
Form form1 = new Form();
WebControl webControl = new WebControl();
form1.Size = new Size(1000, 800);
webControl.Dock = DockStyle.Fill;
form1.Controls.Add(webControl);
//Step 2:
//Put the new WebView (created by the browser engine)
//in the new blank WebControl
webControl.WebView = e.WebView;
webControl.WebView.NewWindow += WebView_NewWindow;
int GiveMeInfo = CommandIds.RegisterUserCommand("GiveMeInfo");
webControl.WebView.Shortcuts = new Shortcut[]
{
//new Shortcut(GiveMeInfo, KeyCode.F2, true, true, false),
new Shortcut(1, KeyCode.F5, true, true, false),
new Shortcut(2, KeyCode.F12, true, true, false),
new Shortcut(3, KeyCode.F4, true, true, false),
};
webControl.WebView.Command += WebView_Command;
webControl.WebView.ObjectForScripting = e.WebView.ObjectForScripting;
webControl.WebView.Closed += WebView_Closed;
//webControl.WebView.Closed += new WebViewClosedEventHandler(form1, new WebViewClosedEventArgs();
form1.FormClosed += Form1_FormClosed;
//Step 3:
//Display the new Form
form1.Show();
//Step 4:
//Notify the browser engine that you "accept" (and display)
//the popup
e.Accepted = true;
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
this.Close();
}
private void WebView_Closed(object sender, WebViewClosedEventArgs e)
{
this.Close();
}
/// <summary>
/// Ctrl + Alt + Key (D)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void WebView_Command(object sender, CommandEventArgs e)
{
switch (e.CommandId)
{
case 1:
webControl1.WebView.Reload();
break;
case 2:
Form form = new Form();
webControl1.WebView.ShowDevTools(form.Handle);
//webControl1.WebView.ShowDevTools(form.Handle);
break;
case 3:
EO.WebBrowser.WebView.ShowDebugUI();
break;
default:
break;
}
}
#endregion
}
Regards
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi, The code in your WebView_Closed event handler is incorrect. Your popup WebView is inside form1, so when your WebView is closed, it should close form1, not your Browser form. In your code you use "this.Close()", where "this" is your Browser form, not form1. You will have to have some code to save form1 so that in your webView_Closed you can close that form instead. Or you can simply use anonymous function like this:
Code: C#
webControl.WebView.Closed += (sender, e)=>
{
//use form1.Close(), not this.Close() here
form1.Close();
}
|
|
Rank: Member Groups: Member
Joined: 2/8/2023 Posts: 14
|
Hi, Thank you for the answer, that seems to work. But the 1st query is pending. Can you please let me know how to open the window with the specified parameters given below?
Code: JavaScript
window.open(uri,frameItemTitle,"left="+winLeft+",top="+winTop+",width="+winWidth+",height="+winHeight+",resizable="+winIsResizable+",scrollbars="+winIsScrollable+"\"");
// The values from the above parameters
'left=230.39999999999998,top=115.36000000000001,width=1075.2,height=593.28,resizable=1,scrollbars=undefined"'
I do not want to specify the form size where WebView is hosting, that should take from window.open. Regards
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi, You would need to examine the corresponding property of the event argument and then position your form accordingly. For example, you can have code like this in your NewWindow handler to honor the left argument:
Code: C#
if (e.Left.HasValue)
form1.Left = e.Left.Value;
The idea is the browser engine only parse the argument for you. It's up to your code to honor it since your code is implementing the container (in your case form1). Thanks!
|
|