views:

548

answers:

2

How would you render a tag cloud within a .NET 2.0+ WinForm application?

One solution that I am thinking of would be using the WebBrowser control and generating to some ad-hoc HTML, but that seems to be a pretty heavy solution.

Am I missing something more simple?

+1  A: 

Well, you'll want a control with these major features:

  • Automatic layout of variable sized string snippets
  • Automatic mouse hit testing

Those are a bit hard to come by in WF controls. A RichTextBox with ReadOnly = true gives you the automatic layout, but not the hit testing. A ListBox with DrawItem can give you variable sized strings and hit testing, but not a natural layout.

I think I would use RTB and make hit testing work with the MouseDown event and GetCharIndexFromPosition(), reading back the tag at the clicked location. You'll need a bit of logic to find the starting and ending white space around the word.

Hans Passant
+2  A: 

How about creating a user control that implements the Flow layout control? You could have a method for "Add(string tagName)" that would create a link label on the fly and add it to the Flow Layout control. The Flow Layout works just like the web, in that controls added to it are put in the order of creation.

Then you only have to add some logic to resize the Link Label based on hit count for that tag.