Difference between vs2005 WebBrowser and AxWebBrowser components?

  • Thread starter Thread starter ESmith
  • Start date Start date
E

ESmith

I'm looking to user a web browser component in VS2005.

I like the functionality in the AXWebBrowser component (from ActiveX
controls page) that allows me to do this:

mshtml.HTMLDocument doc;

doc = (mshtml.HTMLDocument)this.SecureWebBrowser.Document;

mshtml.HTMLButtonElement ButtonTest =
(mshtml.HTMLButtonElement)doc.all.item("ctl00$CenterContent$ctl09$SignUp",
null);

ButtonTest.disabled = true;


Is this possible with the WebBrowser component that I can drop onto my
WinForm in VS2005 - I do not see that capability exposed - what are the
advances/disadvantages of each?



TIA!
 
This should be possible. The WebBrowser control is basically the active
X wrapper, with some extra code to make the interop easier.

There are new elements defined in the System.Windows.Forms namespace
which represent the HTML elements. However, if you want, you should be able
to get at the original objects (through a cast or a property on the object)
and cast to the interfaces exposed through a reference to MSHTML.tlb.

Hope this helps.
 
I like the functionality in the AXWebBrowser component (from ActiveX
controls page) that allows me to do this:

mshtml.HTMLDocument doc;

doc = (mshtml.HTMLDocument)this.SecureWebBrowser.Document;
Is this possible with the WebBrowser component that I can drop onto my
WinForm in VS2005 - I do not see that capability exposed - what are the
advances/disadvantages of each?

AxWebBrowser is an automatically generated wrapper, whereas WebBrowser is
manually customized for .NET. The WebBrowser control has more convenient
methods, such as loading and reading HTML as a string, and should be better
behaved - some people have strange issues with the AxWebBrowser especially
when nested within panels etc.

The snag as you say is that WebBrowser doesn't expose anything like the full
functionality of ShDocVw. However, you can get a reference to the underlying
ActiveX control via the ActiveXInstance property. See here for an example of
when this is necessary:

http://www.itwriting.com/blog/?postid=273

Overall I'd be inclined to use WebBrowser over the AxWebBrowser; or make an
even better wrapper of your own :-)

Tim
Read my tech blog:
http://www.itwriting.com/blog
 
Eliana,
Is this possible with the WebBrowser component that I can drop onto my
WinForm in VS2005 - I do not see that capability exposed - what are the
advances/disadvantages of each?

For simple browser programming, the 2005 WB is MUCH easier to use, but its
power is limited. If you want/need full control, you'll have to wrap it
yourself. The primary functionality that I've found missing in WB 2005 is
frame/iframe support. The control abstracts browsing to the degree that it
hides the fact that navigation events fire for each frame on the page. For
advanced WB programming, you must be aware of this and have control of it.
 
My £0.02 worth...

I've just had to refactor a pile of code that used the AxWebBrowser version
(now uses WebBrowser) because I was getting obscure versioning issues on
some computers (casting complaints to/from mshtml types) - presumably
something to do with the version on the build machine. The WebBrowser
control (which presumably uses AxWebBrowser underneath) didn't appear to
have any such difficulty.

Of course, it helps that my requirements were fairly simple ;-p

Marc
 
Thanks to everyone for there replies!

P.S.

Marc, given the value of the Pound, looks like your opinion is carrying
more weight :-)
 
I'm a .NET noob, so forgive me if this is obvious:

Can anyone give me a hint about how to hook up events from the WebBrower?

The following lets me get the IWebBrowser2 interface:
SHDocVw.IWebBrowser2 pWeb = (SHDocVw.IWebBrowser2)webBrowser1.ActiveXInstance;

However, I can't figure out how to go from that to the delegate:
SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler

I know I can reach down and get the IConnectionPointContainer, etc and I
assume I could maybe wire it up myself, but that seems like the hard way to
go about it.

Thanks
Doug
 
Back
Top