Question WebBrowser Control - DesignMode

Doug Williams

New member
Joined
May 20, 2010
Messages
4
Programming Experience
10+
I keep reading and seeing C# examples of how to make webbrowser control (v2.0 .NET) editable (i.e. user can edit the text displayed in the webbrowser control).

I found this VB example but it causes an error:

Dim axObj As New Object
axObj = WebBrowser1.ActiveXInstance
axObj.document.designmode = "On"

I found this C# example but it also errors:

w1.Document.DomDocument.GetType().GetProperty("designMode").SetValue(w1.Document.DomDocument, "On", null);

NOTE: the "null" at the end is not liked by VB but the rest can be typed and everything shows in drop downs as periods (.) are typed - so it appears to be valid objects / syntax. I ended up having to fix the problem with "null" as follows:

Dim arr(0) as Object
arr(0) = DBNull.Value

w1.Document.DomDocument.GetType().GetProperty("designMode").SetValue(w1.Document.DomDocument, "On", arr)

When run, I get an error:

"#2147221595 Object reference not set to an instance of an object"

Any ideas hot to make webbrowser a control that can be used to edit HTML?
 
Thanks for the info. I replaced the creation of the single element array using DBNulll.Value with just using Nothing and that worked.

Unforunately though, when run, I still get the error:

"#2147221595 Object reference not set to an instance of an object"

Anyone ever get DesignMode turned on for the webbrowser and successfully edit HTML in the control?
 
VB.NET:
Me.WebBrowser1.Document.ExecCommand("EditMode", False, Nothing)
 
Thanks ... but once again, the same error occurs. I am using the webbrowser control provided standard in Common controls with VB Express 2008. It says is v2.0.0.0 .NET Component. Could it be the wrong webbrowser control?
 
Well, stupid me ... I was trying to set the edit mode in the load event for the form with the webbrowser ... the webbrowser object did not yet exist and therefore the error.

This works when placed in the proper place in the code:

Me.WebBrowser1.Document.ExecCommand("EditMode", False, Nothing)
 
Back
Top