By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,556 Members | 1,672 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,556 IT Pros & Developers. It's quick & easy.

HTML in Win Forms?

P: n/a
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.

Nov 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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?

copyco wrote:
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.


Nov 20 '05 #2

P: n/a
Cor
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
Dim doc1 As mshtml.IHTMLDocument2
doc1 = DirectCast(AxWebBrowser1.Document, mshtml.IHTMLDocument2)


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?

Nov 20 '05 #3

P: n/a

Cor wrote:
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
Dim doc1 As mshtml.IHTMLDocument2
doc1 = DirectCast(AxWebBrowser1.Document, mshtml.IHTMLDocument2)

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."

Nov 20 '05 #4

P: n/a
Cor
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.
Nov 20 '05 #5

P: n/a
Hello,

"copyco" <co****@anon.com> schrieb:
Is there a way to display formatted HTML in a Windows form?


311303 WebOCHostVB.exe Hosts the WebBrowser Control in Visual Basic .NET
http://support.microsoft.com/?id=311303

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #6

P: n/a
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.

Cor wrote:
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.


Nov 20 '05 #7

P: n/a
Cor
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

Nov 20 '05 #8

P: n/a
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.InterfaceI sIUnknown)> _
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_hostin g
microsoft.public.inetsdk.programming.webbrowser_ct l

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
"copyco" <co****@anon.com> wrote in message
news:qd****************@newssvr24.news.prodigy.com ...
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.

Nov 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.