Managed HTML rendering

At some point in any WinForms project, you’re bound to need either:

  1. WYSIWYG text entry areas with text formatting
  2. Quick and dirty printed report generation

The obvious choice for both of these things is HTML. No problem! I’ll just drag my HtmlTextBox on the form, set a few properties, and... sadly, no. That control doesn’t exist.* Instead, Microsoft helpfully provides... theRtfTextBox. What year is it again? 2004?

Although I am ambivalent towards HTML, there’s no question that it is a far, far better solution than the nasty, crusty old Rich Text Format. RTF is HTML gone stupid. If you’re ever bored and want to take on a brain-meltingly difficult project, just try writing a RTF to HTML converter. Oh sure, it seems easy enough... but I don’t think anyone can appreciate how profoundly irrational RTF is until they actually sit down and work with it in detail. Ugly doesn’t begin to cover it. Based on my limited research, RTF seems to have evolved as the de facto document storage format for early versions of Microsoft Word, apparently based on the whims of whatever development team was working on Word that week.

To be fair, the RtfTextBox actually isn’t that bad. It’s effectively “free” as far as distribution footprint, and it will work for most basic formatting scenarios including URL and mailto: hyperlinks. In fact, Craig Andera just released a serviceable enhanced RichTextBox. The only problem is that it’s, well, RTF. Just try inserting bulleted text to see what I mean. If you’re dead set on a control that renders HTML, there’s only one solution I’m aware of in .NET: IE interop. Lots of people are doing it:

And it works. Sort of. Like all heavy duty .NET COM interop, you can’t escape the feeling that you’re building a giant house of cards, prone to catastrophic failure at the first gentle breeze. There’s also the matter of our little friend Microsoft.mshtml.dll, a primary interop assembly weighing in at 7.8 megabytes. And god help you if a user doesn’t have IE installed on their system. Inconceivable!

While I’m not against interop per se, it seems like overkill to harness the entire bulk of IE to render a little HTML. What’s really depressing is that there are precious few options, interop or otherwise, for getting proper HTML into a WinForms app. What I’d really like to see is a completely managed, lightweight HTML rendering control written entirely in .NET. In other words, something with the basic features of the RtfTextBox, but using standard HTML conventions. I realize HTML rendering is not exactly trivial, but I think a smallish subset of standard HTML would meet my needs just fine.

*Well, not in this version of .NET. The WebBrowser control will be available out of the box in VS.NET 2005, but it’s the same exact hunk o’ IE interop – but this time, with a pretty Microsoft ribbon on the top.

Related posts

Computers are Lousy Random Number Generators

The .NET framework provides two random number generators. The first is System.Random [http://msdn2.microsoft.com/en-US/library/system.random.aspx]. But is it really random? > Pseudo-random numbers are chosen with equal probability from a finite set of numbers. The chosen numbers are not completely random because a

By Jeff Atwood ·
Comments

Make Mine XCOPY

Steve “what the heck does furrygoat mean” Makofsky crystallized a lot of my thoughts in his recent rant on software installers. One of the biggest advantages of using the .NET framework is the way it enables XCopy deployments for the first time.* Installing a program by copying it to a

By Jeff Atwood ·
Comments

Console apps and AppDomain.CurrentDomain.UnhandledException

This one has me stumped. I’d swear this behaved differently prior to .NET 1.1 service pack 1 (and/or XP SP2), but I can’t prove it. As reported by a CodeProject reader, you’ll get the standard .NET crash dialog in a console app, even if you’

By Jeff Atwood ·
Comments

Creating Even More Exceptional Exceptions

In response to my previous post decrying the lack of a master list of Exception classes for .NET, a helpful reader pointed out a clever little utility buried in the .NET SDK: Program FilesMicrosoft Visual Studio .NET 2003SDKv1.1Binwincv.exe Wincv works well, but it doesn’t allow me to

By Jeff Atwood ·
Comments

Recent Posts

Stay Gold, America

Stay Gold, America

We are at an unprecedented point in American history, and I'm concerned we may lose sight of the American Dream.

By Jeff Atwood ·
Comments
The Great Filter Comes For Us All

The Great Filter Comes For Us All

With a 13 billion year head start on evolution, why haven’t any other forms of life in the universe contacted us by now? (Arrival is a fantastic movie. Watch it, but don’t stop there – read the Story of Your Life novella it was based on for so much

By Jeff Atwood ·
Comments
I Fight For The Users

I Fight For The Users

If you haven’t been able to keep up with my blistering pace of one blog post per year, I don’t blame you. There’s a lot going on right now. It’s a busy time. But let’s pause and take a moment to celebrate that Elon Musk

By Jeff Atwood ·
Comments
The 2030 Self-Driving Car Bet

The 2030 Self-Driving Car Bet

It’s my honor to announce that John Carmack and I have initiated a friendly bet of $10,000* to the 501(c)(3) charity of the winner’s choice: By January 1st, 2030, completely autonomous self-driving cars meeting SAE J3016 level 5 will be commercially available for passenger use

By Jeff Atwood ·
Comments