C# Newbie - mshtml

B

Bill Compton

I have spent the last 5 hours trying to make this work, so I am a bit
frustrated with my ignorance.

I simply want to do the following:

On a WinForm, open a browser object to a particular url.

When I click a button on the WinForm, I want to be able to:
MessageBox.Show(axWebBrowser1.Document.body.innerHTML);

In other words, I want to be able to access the different parts of the DOM.

Ideally, if there were a variable set in the HTML document from code like:

<script>
document.myVar = "I am here"
</script>

Then I would be able to access it from the CSharp form.

Secondly, I want to be able to trigger an event in C# from the browser. The
idea is simple: I want the Javascript in the HTML document to fire a
"HeyPleasePayAttentionToMe" method residing somewhere in my c#.

Pseudo Code:
----test.htm
<html><script>document.myVar="I am here"</script><body>not much of a
body</body></html>
----containWebBrow.cs

using stuffneeded;

namespace stuffIdontUnderstand{
private PleaseDontAssumeIunderstandSyntax
putAButtonOnAForm = new Concept
makeButtonHaveClickEvent
void isMyBrainNow() hooked to the buttonClickEvent

function BrowserJustCalledMe()
end.
-----------------

I also need to be able to compile this on a machine that doesn't have Visual
Studio.

this is the compiler command I have been using this morning.

csc /r:axshdocvw.dll,shdocvw.dll,microsoft.mshtml.dll browTest.cs

I am able to show a browser window inside a form, but I am unable to
interact with it.

Any help would be greatly appreciated.

Thanks,

Bill
 
S

Simon Trew

To do this you need to register your object as the host of the browser. You
can then access it through script (e.g. to fire events) via the "external"
property of the object.

I would suggest reading this MSDN article:
http://www.microsoft.com/mind/1098/advhost/advhost.asp which discusses the
interface and gives examples in VB, which should be easily translatable into
C#, mutatis mutandis.

S.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top