WYSIWYG Editing of HTML in a Windows Forms Control

In a WinForms project that I am working on right now, I have text stored in HTML format in the database. I need a way for novice users to be able to edit this text using a WYSIWYG interface.

The most obvious choice for this in the Windows.Forms control library that is part of the .Net 2.0/3.0 framework is the RichTextBox control. This control gives you a textbox that has functionality similar to the WordPad application found in the Windows OS. It can display formatted pretty well. Aside from the fact that you have to handle all formatting of text in code, RichTextBox it has one major shortcomings: It can only input/output plain text or RTF encoded text. If I wanted to use a RichTextBox control to edit HTML, I would need some way to translate from the source HTML (stored in the DB) to RTF (to be displayed in the RichTextBox) and then back to HTML (to be stored again in the DB). Although I found some components from Sautin Software that seem to do the job, they cost money that I would rather not spend, and add a layer of complexity to my code library that I would rather avoid.

I found a couple of controls that extend the RichTextBox in order to allow input of HTML: An extended RichTextBox to save and load “HTML lite” files by Oscar LondoƱo (Code Project – For .Net 1.1/VS 2003) and RichTextBox that Displays XHTML by Eric Voreis. Both of these controls extend the RichTextBox control in the Windows.Forms library so that it can translate on the fly between RTF and HTML code (so you can input HTML code, see it displayed in the RTB and export HTML code). However, both are old and only support a small subset of HTML tags (although this can be extended in the source, it required knowledge of how RTF works). Also, since they use a RichTextBox control for editing and display, the display is similar but not identical to what you would get using a WebBrowser.

The next method that I found for providing this type of error is HTML Editor by Carl Nolan (Microsoft Consulting Services). This control (written in 2003 for .Net 1.1) modifies a WebBrowser control to allow inline editing and display of HTML. It is professionally written, provides support for many HTML tags and does just about everything that I need (and is free). The one problem is that it is pre-.Net 2.0. It uses a WebBrowser control from before this control was included as part of the Windows.Forms library in .Net 2.0 and thus has to reference Win32 calls and perform other types of acrobatics in order to get the control to function properly. This matters to me because it decreases portability of the control (using Mono, for instance), and makes it harder for me to customize and edit.

WebBrowser-based HTML Editor in action

The control that I am using in the end employs the same general idea used in HTML Editor, but takes advantage of new features (like the native WebBrowser class) provided by the .Net 2.0/3.0 framework and and Visual Studio 2005. A Windows Forms based text editor with HTML output by Kevin DeLafield uses a WebBrowser control with modified functionality to allow WYSIWYG display and editing of HTML text. It provides all of the functionality that I am looking for and allows for easy modifications and customizations in Visual Studio 2005. I recommend that anyone in need of similar functionality take a look at this control.

Visual Studio 2005 Add-Ins and Tools That I Use

I am right now in the middle (about 20% and 18K lines of code through) a pretty substantial Windows Forms project using Visual Studio 2005 (C#). Here are some of the add-ins that I have been using (ranked in order of essential to useful):
Continue reading

What would Raymond Chen say?

I just read a post from Karl Seguin on CodeBetter (quoting Frans, who quoted Soma) that Visual Studio 2002 and 2003 will not run on Windows Vista. Or to quote Soma directly:

However, we will not support Visual Studio .NET 2002 or Visual Studio .NET 2003 as development environments on Windows Vista. You can continue to use Visual Studio .NET 2002 or 2003 on Windows XP to develop applications that can run on Windows Vista.

And how will they be ensuring that VS 2005 is a great development platform for Vista?

Visual Studio 2005 SP1 will run on Vista but will likely have a few compatibility issues.

Uh huh. So the premier IDE for Microsoft development will work on the Vista with “a few compatibility issues”, while the only good IDEs for developing and maintaining ASP.net 1.1 applications will just not work. At all.

What were they thinking?

It looks like Joel Spolsky’s analysis of the situation within Microsoft has really come true. In How Microsoft Lost the API War, Joel identified two camps within Microsoft: the Raymond Chen camp, committed to maintaining software compatibility between versions of the operating system, even if it meant inserting custom API hacks just to make sure that a poorly-programmed SimCity would still work. Said Raymond:

I could probably write for months solely about bad things apps do and what we had to do to get them to work again (often in spite of themselves). Which is why I get particularly furious when people accuse Microsoft of maliciously breaking applications during OS upgrades. If any application failed to run on Windows 95, I took it as a personal failure. I spent many sleepless nights fixing bugs in third-party programs just so they could keep running on Windows 95.

This attitude towards maintaining program compatibility continued through XP. And we are not talking about Microsoft-developed applications, intended to make Microsoft more money. We are talking about third-party games, VB6 apps, old DOS console apps. You name it.

The other camp is the “MSDN Camp” – eternally committed to releasing (and rereleasing, and patching) the newest and greatest technology, compatibility be damned. And as Joel pointed out, starting with VB 6.0 to VB.net, IIS 5.0 to IIS 6.0, new Microsoft products were no longer fully compatible with old ones.

Which brings us to today. Microsoft has made the decision to completely abandon a program which is still used by a very large number (if not most) of programmers who develop for Microsoft technology. Why?

Given the customer feedback that we’ve received since the launch of Visual Studio 2005 indicating the manageability of upgrading from Visual Studio .NET 2003 to Visual Studio 2005, we are focusing our efforts on ensuring VS 2005 is a great development platform for Vista.

Thanks Soma. But no thanks. The migration from Asp.net 1.1 to 2.0 does not work flawlessly. And even if it did (which is probably never, for many of the very complicated webapps out there coded in 1.1), why should we? Why risk breaking something that is already working? In order to use Visual Studio 2005 on Vista, which will hopefully not have too many “compatibility issues”, and will hopefully be able to handle all of our programming needs (covering any .Net framework, as long as it is 2.0)?

No thanks. Personally, unless something drastic changes, I don’t see myself switching from XP to Vista for some time to come. And I am sure that I will not be alone.

ASP.net 2.0 Looking Pretty Slick

First a disclaimer: I have never used Visual Studio 2005 (except for an early beta Express edition) nor have I used ASP.net 2.0 (I plan to start in the next couple of days). I have been doing lots of ASP.net programming and application development using the .Net Framework (1.14322), C#, VS 2003 and SQL Server 2000.

That said, I am getting personally excited (in a professional way) about the improved development potential with ASP.net 2.0

A few things that I have seen recently that have influenced my opinion enough to write the previous sentence:

  • Scott Guthrie has posted an account of how MySpace is using ASP.netand how switching to the new platform (fresumably from ColdFusion) affected their performance:
    • They are processiong 1.5 billion page views per day, reaching 2.3 concurrent users
    • After switching to ASP.net 2.0, their server utilization went down from 85% to 27%!

    So if you are considering the platform, you wont have to be concerned about any scaling or performance issues (assuming you know what you are doing). (I wonder how php would compare, with caching and everything else. Would it even be 50% as efficient as pre-compiled code? 30%?)

  • The ATLAS framework has just received a go-live license with its March CTP release. ATLAS is Microsoft’s version of Ajax for ASP.net. It may not be ROR, but if you check out this demonstration video (worth watching for both the ATLAS demo as well as the demonstration of the new improvements to the product that make development go faster) I hope you will agree that it is definitely something worth trying out.
  • For just a quick taste of other features touched by the upgrade (as well as totally new additions), check out some of the webcasts on the ASP.net Developer Center

They may not ship everything on time…but once they get their products out the door, they (often?!) can really shine.