Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
WebBrowser control not the same from VFP to .NET
Message
From
21/10/2004 21:23:06
Mike Sue-Ping
Cambridge, Ontario, Canada
 
General information
Forum:
Visual FoxPro
Category:
Visual FoxPro and .NET
Environment versions
Visual FoxPro:
VFP 8
OS:
Windows 2000 SP3
Miscellaneous
Thread ID:
00953427
Message ID:
00953589
Views:
17
Hi Rick,

Thanks for the information.

Before I checked your reply, and after posting this question, I figured it out by "Googling" the www and found one site where it was nicely explained.

I kinda liked VFPs simpler way of doing it though :)

Regards,

Mike



>You can't do this sort of thing in .NET because in .NET everything must be strongly typed. So dynamically accessing properties is not really possible.
>
>There are two ways to work around this:
>
>Using Reflection to access properties/methods dynamically
>Import the appropriate object model COM objects
>
>The first requires explicit access to each of the object using the Type object and its various reflection properties like GetField()/GetProperty() etc. to set and retreieve values and call methods. This is a lot of work.
>
>The other alternative is to import MSHTML.DLL as a COM reference or use the Microsoft.mshtml which is ONLY available with VS.NET - if you do make sure to Copy local on that assembly. Either way the assembly for MSHTML will be over 2 megs because the object model is huge.
>
>Once you've done this though you can easily access the Web Browser control with full intellisense:
>
>mshtml.HtmlDocument doc = (mshtml.HtmlDocument) this.Browser.Document
>string Body = doc.body.innerHtml;
>object Item = doc.getElementByID("txtTextBox");
>
>The main thing is that you have to type everything explicitly, so in the case of GetElementById you'd have to cast to the proper Input object and so on.
>
>
>Although it looks like more work it's actually much nicer because you get the support of strong typing plus the ability to have Intellisense help you through the entiry hierarchy.
>
>The only major downer is the need to distribute hte 2 meg Interop assebmly.
>
>+++ Rick ---
>
>
>etc.
>
>
>
>
>What you need to do is in addition to ad
>
>
>>Help!
>>
>>I have a VFP8 form that contains the webBrowser ActiveX control. In VFP I could drill down thru the object hierarchy to get to individual elements in my HTML document.
>>
>>For example,
>>
>>
>>WITH thisform.oBrowser.Document.frames('Content').document
>>	DO CASE
>>		CASE pcViewName = "1"
>>			oBlock = .getElementByID('block1')
>>			oBlock.style.display = ''
>>			oBlock = .getElementByID('block2')
>>			oBlock.style.display = 'none'
>>			oBlock = .getElementByID('block3')
>>			oBlock.style.display = 'none'
>>			oBlock = .getElementByID('block4')
>>			oBlock.style.display = 'none'
>>
>>.
>>.
>>.
>>
>>and this would effectively hide/display certain elements in my page.
>>
>>
>>Now when I try the same thing in C#, the compiler always complains. I'm trying the following syntax:
>>
>>
>>.
>>.
>>.
>>case "1":
>>    webHomePage.Document.frames("Content").document.getElementByID("block1").style.display = "";
>>    webHomePage.Document.frames("Content").document.getElementByID("block2").style.display = "none";
>>    webHomePage.Document.frames("Content").document.getElementByID("block3").style.display = "none";
>>    webHomePage.Document.frames("Content").document.getElementByID("block4").style.display = "none";
>>   break;
>>.
>>.
>>.
>>
>>
>>
>>I get an "'object' does not contain a definition for 'frames'" message.
>>
>>How do I drill down thru the DOM from .NET?
>>
>>TIA
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform