HTMLLabel


What is HTMLLabel ?

First, let's start by saying what it isn't. HTMLLabel is not intended to be an Internet Explorer or Netscape Navigator clone and it is not a web browser in its own right. Neither is it intended to provide a full-blown, all-singing, all-dancing web experience, as (by design) it provides no support for frames or active content. It was developed purely as a way of displaying HTML on a Visual Basic form without the overhead of using the WebBrowser control (which requires Internet Explorer to be installed along with the containing application).

OK, now we know what it's not, what exactly is it ?

HTMLLabel is a free HTML display control designed with the following goals:

  1. To provide a simple way of displaying HTML within a VB application.
  2. Small footprint (the source code is around 150KB).
  3. Minimal external run-time dependencies (there are none, in fact).

HTMLLabel is coded entirely in Visual Basic 6, which means that you can compile it directly into your application with no requirement for external run-time files or additional installation tasks.

Author

HTMLLabel was developed by Woodbury Associates, a UK-based software house specialising in Windows software developed with Microsoft's VB and VBA-enabled toolset. We are constantly developing tools and components for use in our own projects and from time to time we release some of them publicly, which is how you come to be reading this document.

For further information, and details on our other products, visit our products web site or e-mail us.

Licensing

You are free to use HTMLLabel in any way you like, so long as you do not attempt to package it as a commercial component and claim it as your own work. If you are in any doubt about what you intend to do with this software, please contact us before using it. The bottom line is that, although HTMLLabel is free, its ownership and copyright are retained by Woodbury Associates.

Disclaimer

Woodbury Associates does not warrant that the software is error free. Woodbury Associates disclaims all other warranties with respect to the software, either express or implied, including but not limited to implied warranties of merchantability, fitness for a particular purpose and noninfringement of third party rights.

In no event shall Woodbury Associates or its suppliers be liable to you for any consequential, special, incidental or indirect damages of any kind arising out of the delivery, performance or use of the software, even if Woodbury Associates has been advised of the possibility of such damages.

Version History

Version Date Details
0.3.002.01.2002<P> align attribute support added.
Support for centred and right-aligned text enhanced.
<DIV> support added.
<TABLE> bgcolor and height attribute support added.
<TR> height attribute support added.
<TD> bgcolor and valign support added.
Placeholders displayed for missing graphics.
Horizontal scrolling added.
DefaultPadding, DefaultSpacing and UnderlineLinks properties added.
0.2.003.10.2001<IMG> support added.
EnableTooltips property added.
VB URL support added.
Right-aligned text support added.
0.1.009.08.2001<TABLE> support added.
0.0.120.07.2001Version property added.
Design mode handling improved.
0.0.019.07.2001Initial release.

HTML Support

HTMLLabel supports a subset of the standard Hypertext Markup Language (HTML), the full set of supported tags is:

Tag Supported Attributes
Ahref, id, name, title
B
BIG
BLOCKQUOTE
BODYbackground, bgcolor, text, link
BR
CENTER
DIValign
EM
FONTface, color, size
H1-H6
HR
HTML
I
IMGalt, border, height, hspace, src, vspace, width
LI
OL
Palign
SMALL
STRONG
TABLEalign (left and center), bgcolor, border, cellpadding, cellspacing, height, width
THEAD
TBODY
TFOOT
TRheight
THalign, bgcolor, colspan, valign, width
TDalign, bgcolor, colspan, valign, width
U
UL

Using HTMLLabel

Copy the following files into your project's source directory and add them to your VB project:

You should now be able to place an instance of the HTMLLabel control onto a form in the same way that you would put any other control onto a form.

Set the control's appearance, font, etc. in the Properties window.

Set the control's DocumentHTML property at run-time. This is the actual HTML which the control will display.

Supporting Graphics

If you want to support graphics, you will need to implement a handler for the LoadImage event. HTMLLabel requires its container to provide any graphics referenced in your HTML as standard Picture/StdPicture/IPicture objects. The simplest way to do this is to load your graphics using VB's LoadPicture() function, but you can also use graphics stored in ImageList or PictureBox controls.

For example, the following code will load graphics from the same directory as your application:

Private Sub HTMLabel1_LoadImage(Source As String, Image As stdole.Picture)
Set Image = LoadPicture(App.Path & "\" & Source)
End Sub

Integrating HTML and Visual Basic Code

In order to provide a means of programmatically responding to user events in your HTML, HTMLLabel implements VB URLs. This mechanism is similar to the standard JavaScript URLs supported by WWW browsers but differs in that, rather than calling a script function included in the HTML document itself, it allows you to directly call Visual Basic code in the form which contains the HTMLLabel control.

For example, if you place the following code into your form ...

Public Sub SomeFunc(SomeArg As String)
MsgBox SomeArg
End Sub

... and place the following fragment into your HTML document ...

<A href='vb:SomeFunc("Hello, World!")'>say hello</A>

... when you click on the say hello hyperlink, the "Hello, World!" message box will be displayed.

Caveats, limitations and other information:

  1. Referenced VB URLs must be declared Public in the form which contains the HTMLLabel control instance.
  2. You can reference both Functions and Subs, but HTMLLabel cannot use the return value from a function.
  3. The number of arguments to functions/subs is limited to a maximum of eight.
  4. HTMLLabel does not support variables, so all arguments must be constants.
  5. In order to define a VB URL, your anchor's href attribute must start with "vb:".

Known Issues and Limitations

Unlike other HTML renderers, HTMLLabel does not stretch table cells to accommodate their contents. Instead, if table and cell widths are not explicitly given, they are always sized proportionally. You can avoid apparent rendering anomalies due to this sizing algorithm by ensuring that you use explicit table and cell widths, as well as row heights, in your documents.

The rowspan attribute for <TD> elements is not supported. Whilst this might seem insignificant, it is the one limitation which causes the greatest difference between HTMLLabel's rendering of a document and that of other renderers. If you have a document which looks awful when displayed by HTMLLabel (they are not difficult to find), this is the first thing to look for.

Anchors which contain a large amount of text which wraps onto more than one line are not tracked correctly. In this situation, only the portion of the anchor on the last line will actually be active as far as the mouse pointer is concerned.

It is hoped that these issues will be resolved in later releases. In the meantime, it is possible to work around these problems through experimentation and a little imagination.

Properties


Appearance
BackColor
BorderStyle
DefaultFontName
DefaultFontSize
DefaultPadding
DefaultSpacing
DocumentHTML
DocumentTitle
EnableAnchors
EnableScroll
EnableTooltips
UnderlineLinks
Version

Methods


Refresh(Optional PaintOnly As Boolean = True)

Events


HyperlinkClick(Href As String)
LoadImage(Source As String, Image As Picture)


Copyright © 2001-2002 Woodbury Associates