HTML in Win Forms?

  • Thread starter Thread starter copyco
  • Start date Start date
C

copyco

Is there a way to display formatted HTML in a Windows form? Or can I
dynamically create an HTML file and then display that from a Windows
Application? I can create a new HTML file in my project, but how do I
reference it within my code, so I can manipulate it? Thanks.
 
Well, I'm getting closer. I added "SHDocVw.WebBrowserClass" with the
Customize Toolbox. However, I can't load it with HTML because it's
ready-only. I could create a HTML file and then navigate to it, but
that's too clumsy. Anyone have a better idea?
 
Hi copyco,
Well, I'm getting closer. I added "SHDocVw.WebBrowserClass" with the
Customize Toolbox. However, I can't load it with HTML because it's
ready-only. I could create a HTML file and then navigate to it, but
that's too clumsy. Anyone have a better idea?

I think that the answer on your question is given on 19-9-2003 by Charles
Law (shdocvw)
A part of what he did write was
I do not know if you do need the IHTMLDocument2 or just the
mshtml.HTMLDocument.
This was for a scroll activity.
But I think this will set you on the route.

I hope this helps
Cor

End please message us when you did succeed?
 
Cor said:
Hi copyco,



I think that the answer on your question is given on 19-9-2003 by Charles
Law (shdocvw)
A part of what he did write was



I do not know if you do need the IHTMLDocument2 or just the
mshtml.HTMLDocument.
This was for a scroll activity.
But I think this will set you on the route.

I hope this helps
Cor

End please message us when you did succeed?

I don't seem to have the "HTMLDocument" or "IHTMLDocument2" methods
available in my object. Perhaps my object is different in some way, or
I just don't know how to set it up properly. Mine is called "Microsoft
Web Browser."
 
Hi Copyco,
You have to set a reference to microsoft.mshtml
And as an advice, don't do an import that makes your IDE terrible slow,
Use always the full reverence like mshtml.htmldocument or so.
That goes too slow, but when you make an import almost everything becomes
slow in your IDE
Cor.
 
Ok, assuming I get some value loaded into mshtml.htmldocument. How
would I then get that to display in a form? How would I load that into
the web browser object? The one I'm trying to use, the .document method
is read-only. Thanks.
 
Copyco
You have now a document according to the DOM (document object model).
It is not the smallest object model, to do more with it; you would have to
do the same as most of us, investigate the object model and see what you can
do with it.

The DOM is the most important object model that IE works with.
I don't know if it fits for you. But you have now two major object models to
do your work.
The webbrowser and the DOM, but both are not the easiest ones.

Succes

Cor
 
Hi

To create an HTML document in memory, I recommend the following:

<code>
Imports System.Runtime.InteropServices

' IPersistStreamInit interface
<ComVisible(True), ComImport(),
Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IPersistStreamInit
Sub GetClassID(ByRef pClassID As Guid)

<PreserveSig()> Function IsDirty() As Integer
<PreserveSig()> Function Load(ByVal pstm As UCOMIStream) As Integer
<PreserveSig()> Function Save(ByVal pstm As UCOMIStream, ByVal fClearDirty
As Boolean) As Integer
<PreserveSig()> Function GetSizeMax(<InAttribute(), Out(),
MarshalAs(UnmanagedType.U8)> ByRef pcbSize As Long) As Integer
<PreserveSig()> Function InitNew() As Integer
End Interface

Private Function CreateDocument() As mshtml.IHTMLDocument2

Dim doc2 As mshtml.IHTMLDocument2
Dim ips As IPersistStreamInit

' Create a new document
doc2 = New mshtml.HTMLDocument

ips = DirectCast(doc2, IPersistStreamInit)

' Initialise the document
ips.InitNew()

' Wait until initialisation is complete
Do Until doc2.readyState = "complete"
Application.DoEvents()
Loop

Return doc2

End Function
</code>

This will create an initialisesd document that you can manipulate.

Include a reference to Microsoft.mshtml in your project, but as Cor
suggested, do not include an imports for mshtml, but qualify declarations
with it instead. Mshtml contains hundreds of interfaces that take a
noticeable time to load each time you type Dim x As ...

Once you have an interface to the document (doc2) you can manipulate it
through this and other interfaces.

ips.Load will load the document from a stream, but remember to wait for
doc2.readstate to be "complete" before accessing the document; docuemnts are
loaded asynchronously.

Feel free to post back further questions. You may also like to look at

microsoft.public.inetsdk.programming.mshtml_hosting
microsoft.public.inetsdk.programming.webbrowser_ctl

I tend to post answers to this type of question here as they crop up quite
frequently. When I have a moment ( ;-) ) I will try to put together a small
app that demonstrates a lot of the techniques.

HTH

Charles
 
Back
Top