The Meadows

Fortnightly ravings of an idea man.

Contact me on Gmail. My address is superjodash.

View John Kemp's profile on LinkedIn

Idea - Html for WinForms

I’m thinking about creating a library which does the following (pseudocode):

string html = @”
<html>
<head>
<title>My HtmlForm</title>
<!— Don’t need unless referencing a special control —>
<!— This is just an example —>
<link rel=”using” href=”System.Windows.Forms”/>
<script lang=”c#”>
protected void OnButtonClick(object sender, EventArgs e) {   MessageBox.Show(‘Click!’);
}
</script>
</head>
<body>
<wf:tabcontrol id=”tabControl1” dock=”DockStyle.Fill”>
<wf:tabpage text=”Tab 1”>
<wf:button id=”Button1” text=”  Push Me  ” onClick=”OnButtonClick” style=”BackColor:Colors.Black;ForeColor:Colors.White;”/>
</wf:tabpage></wf:tabcontrol>
</body></html>”;
HtmlForm form = new HtmlForm(html);
Application.Run(form);

Why HTML when we have WPF? Well, for one thing, I already know HTML. Secondly, it’s easier than WPF. Thirdly, WPF is kind of slow and GDI+ is already established. I’m sure I can keep going.

Mostly I’m interested in the layout aspects of HTML. It’s nicer. I think it could even support (eventually) some CSS.

What about caveats? It has to be strict XHTML so it can be parsed efficiently. Also, not everything will be supported. There will have to be versions (which don’t necessarily follow the HTML standards - like 3.0 or 4.2). WinForms controls have the namespace “wf” so the parser knows which ones to create. Any WinForms control can be added explicity using this qualifier.

I don’t think this would be super hard to do a small sample. I think the initially supported items would include:

  • button (Button)
  • textbox (TextBox)
  • textarea (TextBox with autosize == false)
  • select (ComboBox)
  • ul (Radio- or CheckBoxList?)
  • img (PictureBox)
  • h1 - h7 (Label)
  • p or div (Panel)
  • table (set controltype=
    • TableLayoutPanel
    • FlowLayoutPanel
    • DataGridView)
  • frameset (SplitContainer)

Every control will have the following properties:

  • id (name of control)
  • style (css syntax for settin simple properties)
  • properties of each control
    • BackColor
    • ForeColor
    • Text
    • Padding
    • Margin
    • etc

I’m still working on code behind paradigm. I’m not sure about that. Obviously you could do script tags like in ASP.NET but you end up with no intellisense or design time helpers. In fact, you’d have to run it to find out anything. Ideally there would be a VSIP template defining a .wfh file (WinFormHtml) that is HTML and has a code behind section. Basically ASP.NET except for WinForms.

I think the idea still has merit. Especially since I don’t particularly care for designing my WinForms apps as they currently are.

Ultralite Powered by Tumblr | Designed by:Doinwork