Welcome to MSDN Blogs Sign in | Join | Help

Windows Forms Control In Browser scenario (introduction)

Recently I have been hearing from more and more people who are embedding Windows Forms controls into webpages and I thought that I would put together a series of blog posts on this technique.

Since the original release of .NET Windows Forms has supported hosting controls inside of a web browser (Internet Explorer).  The control would be loaded inside the internet explorer process and would be visually represented inline with the other contents of the html page.  Here's how it works.

First we'll create a really simple control:

File: SimpleControl.cs

using System;
using System.Drawing;
using System.Windows.Forms;

public class GreenControl:Control {
  public RedControl() {
   this.BackColor = Color.Green;
  }
}

And a really simple web page to host it:

File: Host.html

<html>
  <head><title>Simple control host</title></head>
<body>
  <H1>Simple control host page</H1>
  <object width=20 height=20 classid="SimpleControl.dll#GreenControl"></object>
</body>
</html>

Then compile the control with the command line: csc /target:library SimpleControl.cs

I now have 3 files (SimpleControl.cs Host.html and SimpleControl.dll) in a directory.  I copy the last two files (.html and .dll) to a web server somewhere and navigate to the html file to see a completely uninteresting web page with a small green square of managed code.

Published Tuesday, January 10, 2006 2:23 PM by AndrewDownum
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Windows Forms Control In Browser scenario (introduction)

Tuesday, January 10, 2006 6:38 PM by Jason
Thats an interesting example you got there ;)

Now, in this scenario, it looks as though the browser and the component are on the same development machine. So my question is ... Does the component run server-side, or client-side? And how do you set it up to work one way or the other?

I mean, I could experiment myself, but then I would be depriving you of another perfectly good blog topic.

# re: Windows Forms Control In Browser scenario (introduction)

Tuesday, January 10, 2006 10:43 PM by Kris
I have seen this in .NET 1.x version (I think it was a Chris Sells's article) but it used to be a bit more involved than this (the HTML tags I mean). It looks very simple now - Is this specific to Whidbey?

# Hosting Controls in Internet Explorer

Saturday, February 11, 2006 4:08 AM by Kirk Allen Evans' Blog
I recently tried to do a simple demo of hosting a control in IE to show how the CLR will behave when...

# re: Windows Forms Control In Browser scenario (introduction)

Tuesday, February 14, 2006 4:32 PM by AndrewDownum
Jason.  All execution for the control hosted in the browser will occur on the client machine (the one running Internet Explorer).  There is no way to configure this to work differently.  If you want to run some code on the server, you can write custom ASP.NET or web service code on the server and then communicate back and forth between the control in the browser and the server.

Kris.  This stuff is the same in .NET 1.X and 2.0  I just boiled down my samples to simpler versions.  There is a lot of more complicated stuff that you can add in to support other scenarios that I have left out thus far.  (more posts to come)

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker