Web Browser to handle pop ups within the application - browser

I am trying to use the WebBrowser control to launch a new form for popups instead of it opening in IE. I have tried to use the AxWebBrowser instead to get the popups which works with NewWindow3 event and just doing e.ppDisp = AxWebBrowser.Application, but there are many limitations that come with AxWebBrowser. So instead I am trying to Extend the normal WebBrowser to include the NewWindow3 event like the AxWebBrowser but running into problems. With e.ppDisp = AxWebBrowser.Application I am getting errors: "InvalidVariant was detected" followed by "Specified OLE variant is invalid" if I continue.
Note: This is my first time extending a class so I could be over looking something simple. If I try just navigating to the new URL in the new window, I get java script errors from the site.
I have updated the code base on comments. Have removed the ExtendedWebBrowser class for a munch smaller and nicer version. Here is the New Code:
From the main form and a very similar BrowserPopup form -
Protected Overrides Sub OnLoad(ByVal e As EventArgs)
MyBase.OnLoad(e)
nativeBrowser = DirectCast(ExtendedWebBrowser1.ActiveXInstance, SHDocVw.WebBrowser)
AddHandler nativeBrowser.NewWindow3, AddressOf nativeBrowser_NewWindow3
AddHandler nativeBrowser.WindowClosing, AddressOf nativeBrowser_WindowClosing
End Sub
Private Sub nativeBrowser_NewWindow3(ByRef ppDisp As Object, ByRef Cancel As Boolean, ByVal dwflags As UInteger, ByVal bStrUrlContext As String, ByVal bstrUrl As String)
Dim popup = New BrowserPopup()
popup.Show(Me)
popup.browserPop.DocumentText = bStrUrlContext
ppDisp = popup.browserPop.ActiveXInstance
End Sub
Private Sub nativeBrowser_WindowClosing(ByVal IsChildWindow As Boolean, ByRef Cancel As Boolean)
MsgBox("working?") '<<<Doesn't Trigger>>>
End Sub
Protected Overrides Sub OnFormClosing(ByVal e As FormClosingEventArgs)
MyBase.OnFormClosing(e)
End Sub
Also, if it helps, here is the scripting from the page that should be able to close the popup form but just seems to deactivate the WebBrowser instead.
<table isListBtn="false" cellpadding="0" enabled="true" class="buttonBorderBlue"
cellspacing="0" border="0" onClick="if (typeof(workpaneMediator_toolbar)!='undefined')
workpaneMediator_toolbar.onSelect('CANCEL_ACTION', this)"
actionType="CLOSE_WINDOW_TYPE" id="workpaneMediator_toolbar_CANCEL_ACTIONWrapper"
nowrap><tr><td class="buttonBlueTD">

You're right that WindowClosing doesn't get fired for Winforms WebBrowser Control, I confirm that. It appears to be a long-time bug in .NET WebBrowser ActiveX hosting code, which has never been addressed. Check this post for more details and a possible workaround.
Another possible workaround may be to host WebBrowser ActiveX Control directly via AxHost class, in which case WindowClosing gets fire correctly. Example:
C#:
using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WebBrowserApp
{
// MainForm
public partial class MainForm : Form
{
WebBrowser webBrowser;
public MainForm()
{
InitializeComponent();
InitBrowser();
if (this.webBrowser.Document == null && this.webBrowser.ActiveXInstance == null)
throw new ApplicationException ("Unable to initialize WebBrowser ActiveX control.");
var ax = (SHDocVw.WebBrowser)this.webBrowser.ActiveXInstance;
ax.NewWindow2 += (ref object ppDisp, ref bool Cancel) =>
{
var popup = new RawBrowserPopup();
popup.Visible = true;
ppDisp = popup.WebBrowser.ActiveXInstance;
};
this.Load += (s, e) =>
{
this.webBrowser.DocumentText = "<a target=\"_blank\" href=\"javascript:'<button onclick=\\'window.close()\\'>Close</button>'\">Go</a>";
};
}
// create a WebBrowser instance
void InitBrowser()
{
this.webBrowser = new WebBrowser();
this.webBrowser.Dock = DockStyle.Fill;
this.Controls.Add(this.webBrowser);
this.webBrowser.Visible = true;
}
}
// RawWebBrowser
public class RawWebBrowser : AxHost
{
public RawWebBrowser()
: base("8856f961-340a-11d0-a96b-00c04fd705a2")
{
}
public event EventHandler Initialized;
protected override void AttachInterfaces()
{
if (this.Initialized != null)
this.Initialized(this, new EventArgs());
}
public object ActiveXInstance
{
get
{
return base.GetOcx();
}
}
}
// RawBrowserPopup
public class RawBrowserPopup : Form
{
RawWebBrowser webBrowser;
public RawWebBrowser WebBrowser
{
get { return this.webBrowser; }
}
public RawBrowserPopup()
{
this.webBrowser = new RawWebBrowser();
this.webBrowser.Initialized += (s, e) =>
{
var ax = (SHDocVw.WebBrowser)this.webBrowser.ActiveXInstance;
ax.NewWindow2 += (ref object ppDisp, ref bool Cancel) =>
{
var popup = new RawBrowserPopup();
popup.Visible = true;
ppDisp = popup.WebBrowser.ActiveXInstance;
};
ax.WindowClosing += (bool IsChildWindow, ref bool Cancel) =>
{
Cancel = true;
this.Close();
};
};
this.webBrowser.Dock = DockStyle.Fill;
this.Controls.Add(this.webBrowser);
this.webBrowser.Visible = true;
}
}
}
VB.NET:
Public Class Form1
Dim webBrowser As WebBrowser = New WebBrowser()
Sub New()
MyBase.New()
Me.InitializeComponent()
webBrowser.Dock = DockStyle.Fill
Me.Controls.Add(webBrowser)
webBrowser.Visible = True
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.webBrowser.DocumentText = "<a target='_blank' href='javascript:""<button onclick=\""window.close()\"">Close</button>""'>Go</a>"
Dim ActiveX As SHDocVw.WebBrowser = Me.webBrowser.ActiveXInstance
AddHandler ActiveX.NewWindow2, AddressOf WebBrowser_ActiveX_NewWindow2
End Sub
Private Sub WebBrowser_ActiveX_NewWindow2(ByRef ppDisp As Object, ByRef Cancel As Boolean)
Dim popup As RawBrowserPopup = New RawBrowserPopup()
popup.Visible = True
ppDisp = popup.WebBrowser.ActiveXInstance
End Sub
End Class
Public Class RawWebBrowser
Inherits System.Windows.Forms.AxHost
Sub New()
MyBase.New("8856f961-340a-11d0-a96b-00c04fd705a2")
End Sub
Event Initialized(sender As Object, e As EventArgs)
Protected Overrides Sub AttachInterfaces()
RaiseEvent Initialized(Me, New EventArgs())
End Sub
Public ReadOnly Property ActiveXInstance() As Object
Get
Return MyBase.GetOcx()
End Get
End Property
End Class
Public Class RawBrowserPopup
Inherits System.Windows.Forms.Form
Dim WithEvents rawBrowser As RawWebBrowser = New RawWebBrowser()
Sub New()
MyBase.New()
rawBrowser.Dock = DockStyle.Fill
Me.Controls.Add(rawBrowser)
rawBrowser.Visible = True
End Sub
Public ReadOnly Property WebBrowser() As Object
Get
Return rawBrowser
End Get
End Property
Private Sub rawBrowser_Initialized(sender As Object, e As EventArgs) Handles rawBrowser.Initialized
Dim activeX As SHDocVw.WebBrowser = rawBrowser.ActiveXInstance
AddHandler activeX.NewWindow2, AddressOf activeX_NewWindow2
AddHandler activeX.WindowClosing, AddressOf activeX_WindowClosing
End Sub
Private Sub activeX_NewWindow2(ByRef ppDisp As Object, ByRef Cancel As Boolean)
Dim popup As RawBrowserPopup = New RawBrowserPopup()
popup.Visible = True
ppDisp = popup.WebBrowser.ActiveXInstance
End Sub
Private Sub activeX_WindowClosing(IsChildWindow As Boolean, ByRef Cancel As Boolean)
Cancel = True
Me.Close()
End Sub
End Class

Related

Is there any way to change dialog cancel button in x++?

I am using Dialog class to make my dialog. I added there custom lookup and field, but it looks like cancel button doesnt work as it supposed to work. I dont know a lot about Dialog class and how it works... Is there any suggestions how to change Cancel button to its normal function - cancel the dialog. Right now it throws info that is supposed to throw out on Process when u press Ok on Dialog.
My current code:
class copyline
{
public void clicked()
{
Counter createdRecordCnt;
Trans trans;
Table table;
MultiSelectionHelper helper = MultiSelectionHelper::construct();
JournalId journalId;
helper.parmDatasource(Trans_DS);
MyClass MyClass= new MyClass();
MyClass.dialog();
trans = helper.getFirst();
while(trans.RecId != 0)
{
MyClass.parmJournalTrans(trans);
MyClass.parmJournalId(JournalId);
if (journalId)
{
MyClass.parmJournalTrans(trans);
MyClass.parmJournalId(JournalId);
MyClass.run();
}
else
{
if (MyClass.prompt())
{
MyClass.run();
journalId = MyClass.parmJournalId();
}
}
createdRecordCnt++;
trans = helper.getNext();
}
Info(strFmt("#LabelFile:Label", createdRecordCnt, MyClass.parmJournalId()));
}
}
I have class with Dialog object, validations, lookup etc.
Dialog on class:
public Object dialog()
{
Dialog dialog = super();
FormBuildStringControl control;
dialog.caption("#LabelFile:Label");
Journal = dialog.addField(extendedTypeStr(MyEDT));
control = Journal.control();
control.registerOverrideMethod(methodstr(FormStringControl, lookUp), methodStr(MyClass, journalTypeLookup), this);
return dialog;
}

Error accessing product object method - Lotus Notes

I'm getting this error "Error accessing product object method" on Call mySqlTableObj.init(url,user,password)
here is the lotusscript script library:
Dim jsDU As New JAVASESSION
Dim mySqlTable As JAVACLASS
Dim mySqlTableObj As JAVAOBJECT
Set mySqlTable = jsDU.GetClass("org.piu.MySQLTable.MySQLObject")
Set mySqlTableObj = mySqlTable.Createobject()
Call mySqlTableObj.init(url,user,password)
Set getMySQLTableObject = mySqlTableOBJ
here's the java script library:
public void init( String url, String un,String pd) {
this.url = url;
this.un = un;
this.pd = pd;
}
I do not get this error all the time. Sometimes it does not appear sometimes it does. Can anyone help me with this?
Thanks!

Why I cant Select element in DockablePane when i use IExternalEventHandler

i want select element when i click button.i use IExternalEventHandler ,but i cant use
method: pickobject/pickobjects ,i change the method to pickPoint the hander run success.
event
public class ExecuteEvent : IExternalEventHandler
{
public string ElementId { get; set; }
public void Execute(UIApplication app)
{
UIDocument uidoc = app.ActiveUIDocument;
Autodesk.Revit.DB.Document doc = uidoc.Document;
Autodesk.Revit.UI.Selection.Selection sel = uidoc.Selection;
Autodesk.Revit.DB.Reference re = sel.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
Autodesk.Revit.DB.XYZ point = sel.PickPoint("select");
ElementId = re.GetType().Name;
}
public string GetName()
{
return "ExecuteEvent";
}
}
hander
Exc = new ExecuteEvent();
ExternalHander = ExternalEvent.Create(Exc);
button click
private void Button_Click(object sender, RoutedEventArgs e)
{
ExternalHander.Raise();
SetLabelText(Exc.ElementId);
}
Apparently, the external event handler does not provide you with a valid user interface context. To get such a context, you might want to subscribe to the Idling event instead. That event is called when Revit has nothing else to do and hence is free to interact with the user.

What's the proper way to edit text in objectlistview

I have an objectlistview with 4 columns and a dynamic number of rows, I'm struggling with programmable editing a cell text value, and optionally change the forecolor
I've read everything and anything that I could put my hands on, but couldn't find any valid and right to the point example on how to do it.
the ObjectListView is created this why
List<VideoItem> list = new List<VideoItem>();
foreach (dynamic item in VideoItems)
{
list.Add(new VideoItem { Index = (int)item.index, OldName = (string)item.oldname, NewName = (string)item.newname });
}
olv1.AddObjects(list);
VideoItem class look like this
private class VideoItem
{
public int Index;
public string OldName;
public string NewName;
}
but i need to programmably edit a cell text on event. I'm doing some logical operations on other cell at the end im storing the result to to cell next to it.
You should be storing the result (making the change) to the underlying model object and then call RefreshObject(myModelObject);
About the forcolor, i need to change only the cell I've changed
"To change the formatting of an individual cell, you need to set UseCellFormatEvents to true and then listen for FormatCell events."
Take a look at this.
Just to add to Rev1.0 Answer, i needed to update the object that contains the items (in my case a List) then, use olv1.RefreshObject(list); flow by olv1.BuildList(true);
the olv1.BuildList(true); refresh the GUI immediately.
here a small code snippet to make thing bit more clear
it's changing the data in column 3 when a checkbox is checked.
using System.Collections.Generic;
using System.Windows.Forms;
namespace Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Initializeolv();
}
private class VideoItem
{
public int Index;
public string OldName;
public string NewName;
}
private List<VideoItem> list = new List<VideoItem>();
private void Initializeolv()
{
for (var i = 1; i <= 10; i++)
{
list.Add(new VideoItem { Index = i, OldName = $"old{i}", NewName = $"new{i}" });
}
olv1.AddObjects(list);
}
private void olv1_ItemChecked(object sender, ItemCheckedEventArgs e)
{
list[e.Item.Index].NewName = "new200";
olv1.RefreshObject(list);
olv1.BuildList(true);
}
}
}

How do I create a program that details files and their sub directories?

There is a program that I am working on and Im absolutly lost even at how to begin this. I am using Visual Studio C# Windows App Form.
What I need to do is allow the user to enter any path location they want and the program will return the Name of the file/folder; Path; date and size, and this will also be done for sub directories.
I found some code in the MSDN site and I am trying to use it and modify it for the first part of this project, but keep receiving error messages. Some of the messages indicate that there is more than one entry ie (static void Main() and using namespace Detailed).
This is what I have so far, a form with rich text box and the FolderBrowserDialog and it seems as I can't get beyond this point without so many errors.
This is under Form1.Designer.cs:
<i>namespace Detailed
{
partial class Form1
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.SuspendLayout();
//
// folderBrowserDialog1
//
this.folderBrowserDialog1.HelpRequest += new System.EventHandler(this.folderBrowserDialog1_HelpRequest);
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(12, 32);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(167, 23);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "";
//
// openFileDialog1
//
this.openFileDialog1.FileName = "openFileDialog1";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.richTextBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
}
}
For the For1.cs this is what I have so far:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
public class FolderBrowserDialogExampleForm : System.Windows.Forms.Form
{
private FolderBrowserDialog folderBrowserDialog1;
private OpenFileDialog openFileDialog1;
private RichTextBox richTextBox1;
private MainMenu mainMenu1;
private MenuItem fileMenuItem, openMenuItem;
private MenuItem folderMenuItem, closeMenuItem;
private string openFileName, folderName;
private bool fileOpened = false;
public partial class Form1 : Form
{
public Form1()
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e)
{
}
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// FolderBrowserDialogExampleForm
//
this.ClientSize = new System.Drawing.Size(284, 262);
this.Name = "FolderBrowserDialogExampleForm";
this.ResumeLayout(false);
}
}
I'm still new to programing and hope I can get this figured out asap as I was requested to have this no later than Thursday morning est. I had the Rich TextBox in the Form, but removed it because of too many errors.
This is the code I found. I know this is just part of what I need to do, but when reading through the code I noticed that maybe I can apply what is needed to the form and then break up the code and put the pieces of code where I need them. This is the code I am following
Here is an error message I am receiving with Form1.Designer.cs - there are 14 of these same errors:
‘Detailed.form1’ does not contain a definition for ‘Form1_Load’ and no extension method ‘Form1_Load’ accepting a first argument of type ‘Detailed.Form1’ could be found (are you missing a using directive or an assembly reference?)
The first thing you want is a dialog prompting the user for a directory.
So get rid of all that code, start a new project win form and place a textbox in your form and a button in your form.
Simple enough one text box and one button. Now in the click event of your button "Browse", have you, you write code to open an instance of the FolderBrowserDialog class and you .ShowDialog().
To get this path:
Here is a sample screen output:
The code is fairly straightforward, look at my picture and how much code i have to do this.

Resources