Invoking Windows Forms controls from the web browser
How do Java applets fit into the world of .NET? The short answer is, "they don’t", but it is possible to achieve a similar design using Windows Forms controls. This short guide assumes that you have some previous experience in web development on the Windows platform.
Introduction
ASP.NET may or may not be the best thing since sliced bread, but it is a relatively new kid on the block. I first realized its true power in 2001 during a developer conference on a sunny day in downtown Boston. That is, it was sunny until Don Box decided to take off his tshirt in front of the audience, but that is another story.
ASP.NET has now been around for several years and every day it attract new arrivals. I was having lunch at a local Greek restaurant with an old friend of mine, who asked me: Is there an adequate equivalent to Java applets in .NET?
That is a very good question. Here is one answer and a way to achieve a similar effect.
Creating a WinForm control
Start Visual Studio, create a new C# project using the Windows Control Library and name it WinFormControl.

This will give us a blank canvas for our artistic urges. Try to stand the corny default names for now. Just create a button and a few text labels.

Name one of the text labels lblMessage. In the click event for the button, write something like the following code:
Compile this mighty control and copy the DLL file into a new directory called something nice.
HTML
Next step is to create the HTML page where we embed the control. Create a text file with the following content:
UserControl1.dll is the name of the assembly created in the previous step, WinFormControl is the namespace and UserControl1 the control itself. Name the file ControlHost.html and place it where you placed the DLL file.
Web server configuration
Time to bring this magnificent creation into the world. Start the IIS management snap-in and create a new virtual directory: Right-click "Default Web Site", select New -> Virtual Directory, specify alias WinFormsControl and locate the directory where you placed the DLL and HTML files. The default access permissions, "Read" and "Run scripts" will do fine.

View result
Start your Internet Explorer browser (sorry, this won’t work in Mozilla and other nicer browsers) and navigate to
http://localhost/winformscontrol/controlhost.html
The control will load quickly into the HTML page. Click the button and verify that the message is displayed.

As you can see, this may be done quite quickly. Happy coding!
Comments
No comments yet.
Leave a reply
Your email address will not be published. Required fields are marked *