This project is read-only.

HtmlLabel Rendering

Feb 22, 2013 at 2:18 PM
I'm seriously scratching my head over some of the behavior for the rendering used in a label.

With AutoSize = True (min/max are 0 for the label), content is rendered at the narrowest width possible rather than the default (for either HTML content or the Windows Forms Label) of taking as much room as it can. With a browser, the parent container will constrain content while in the case of a normal Label it will continue on past the borders. At a minimum, I would expect the normal Label behavior (extending past the borders) and ideally it would constrain itself to the parent.

The behavior is the same with AutoSize = False and AutoSizeHeightOnly = False, though in this case, if I set a label to a particular size, I expect the content to run past the border of the label (as opposed to the border of the parent above).

It was only by setting a specific size, anchors, AutoSize = False and AutoSizeHeightOnly = True (plus marking the html as centered) that I could get a semblance of normal operation out of the HtmlLabel. Other than a transparent background (a strange limitation on the HtmlPanel, btw) I'm not sure why I would ever use the HtmlLabel if I have to set it up like the panel in the first place.
Feb 25, 2013 at 8:07 AM
Sorry about that, dynamic width is the less common scenario so there are a few bugs there, will be fixed in v1.4

The major differential to use HtmlPanel or HtmlLabel is size and scrollbars.
If the size of the control depends on the html content the HtmlLabel should be used.
If the size is set by some kind of layout then HtmlPanel is more suitable, also shows scrollbars if the html contents is larger than the control client rectangle.
Also the HtmlPanel scrollbars making transparency is kinda weird so it is not allowed.

AutoSize = AutoSizeHeightOnly = false (has bug in v1.3, will be fixed in v1.4)
The label size will not change by the html content. MaximumSize and MinimumSize are ignored.

AutoSizeHeightOnly = true
This is a special case that I believe very missing from WinForms label.
The width of the label is set and will not change by the content, the height is adjustable by the html content with restrictions to the MaximumSize.Height and MinimumSize.Height values.

AutoSize = true (has bug in v1.3, will be fixed in v1.4)
The width and height is adjustable by the html content, the width will be longest line in the html, MaximumSize.Width will restrict it but it can be lower than that.

Note: Not rendering outside control client rectangle is fundamentally the way WinForms works.

Not sure why you needed to center the html though..
Feb 26, 2013 at 3:40 AM
Not sure why you needed to center the html though..
Once the HtmlLabel will resize itself based on the content, I won't need to (centering via <center></center> has another issue I'll mention in a moment). The current use case for the HtmlLabel is to replace a set of controls I'm using to render the content in my example. I have five label controls (two which give me the dynamic content/bold text required for the display). I have these set in a panel (itself inside a TableFlowPanel with no anchors so it floats in the center of the row). When the content changes, I go through a centering pass to position all the labels so it appears as one block of text. With HtmlLabel auto-sized, I can just let the control replace the panel/labels and let the TableFlowPanel position the control when it changes size.

I haven't replaced these labels yet, but if I go forward with HtmlLabel as it stands now, I would have to set AutoSizeHeightOnly = true, stretch the HtmlLabel across the panel, anchor it left/right and then force an invalidate on the HtmlLabel whenever the panel changes size. The reason for the invalidate is the label does not update itself whenever it's size changes. It probably should take another render pass on resize (for any and all location-setting html/css) to make sure the content is positioned properly for the new size.
Feb 26, 2013 at 8:22 AM
From your description I would say using AutoSizeHeightOnly = true and center is the best option.
You just anchor the label and let it layout the text by itself.
If everything is set correctly there is no need to invalidate or manually layout anything.