Props to Sven Groot on Channel 9 and Ben the Developer for all the help, thanks!
This is going to be my first tutorial. It's not final, end-all, documentation on this subject. But it is what I have gotten from Channel9 discussions and online documentation. It will walk you through setting up a .Net Applet.
First of all, what is a .Net Applet? An Applet is basically a small application hosted in a larger application, in this case, the browser. Most common are Java Applets, but they are not the only ones. Items in the Windows Control Panel are called Control Panel Applets. .Net Applets are called that because they resemble Java Applets, but that is not their official name. Generally, the procedure I am about to describe is called 'Hosting Windows Forms controls in Internet Explorer'.
How do you create a .Net Applet? Very basically, you create a Windows Forms user control. That's right, you write Windows Forms code and your browser (Internet Explorer only) handles it. Then you put an <object> tag into your html and specify some information about the Applet (the dll file, namespace, and class).
How does this work? (You can skip this if you want to get right to coding.) Well, Internet Explorer is able to run .Net controls probably by using COM to host mscoree.dll. (If you know more, let me know) If the user/client has the .Net Framework installed, and Internet Explorer 6.0 (I am not sure of 5) your user control will simply be gobbled up and used as a local control.
Security
'Whoa! What is Microsoft doing to us? Think of the hole this could open up!!!', you say. Calm down. It runs in a 'sandbox'. A special zone that limits what the control can do. It won't let you access local files with the exception of the OpenFileDialog box, and then can only use the dialog box's OpenFile() method. You cannot use the SaveFileDialog. So you don't have to worry about some one messing with your hard drive. (To see which permissions an assembly has for all the different zones, you can go to Control Panel/Administrative Tools/.Net Framework 1.1 Configuration, and then under Runtime Security Policy/Machine/Code Groups/All Code.)
To the code
If you've done a windows form control, or even just a windows form (controls aren't much harder than forms themselves, just a different mindset) you can do this .Net Applet stuff.
The Control
Create a new Windows Control Library project (demoControl). Drop your items and code into it and compile. Okay, okay, an you want an example. Let's do this (thanks Sven):
We have our project. It should default with a User Control. This looks like a
Windows Form grid, but without the title bar. Quick reason behind this, it's
NOT A FORM. It's a control. Your form will have the title bar, and any menus.
(You also cannot drag a Main Menu component to this grid.)
So, drag some controls to your User Control (myControl). In our demo we are going to use a Combo Box and a Label. Very simple. Fill your Combo Box with some items. Whatever you feel like. I'm using different types of computer systems. (Laptops, Tablet PCs, Desktops)
Now we need to create some code. Double click on your combo box. The designer will create a method to handle the SelectedIndexChanged event. For example purposes, simply put some code in that takes the combo box text and drops it into the Label.Text property. (VB: Me.Label10.Text = Me.ComboBox1.SelectedText) We're done for now, compile it and on to the HTML.
HTML Source
For simplicity's sake, create a Web Project. In your default page put a tag like this:
<object id='ControlID' classID='PathToAssemblyFile.dll#Qualified.Class.Name' />
Place the complied DLL from your control project in the same virtual directory as the HTML. Then browse to it. Your control should pop up. As you select the items, the label should change. You have just created a .Net Applet. (Note: If you run this from the local machine or an Intranet Webserver you will not be as restricted as a control run from the Internet zone. Keep this in mind when your users say it's not working out of the office.) Here's an example of the html:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="demoPage.aspx.vb" Inherits="demoWebProj.demoPage" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Cropping an Image</title>
</HEAD>
<body id="bdyElem" runat="server">
<form id="Form1" runat="server">
<OBJECT id="myControl" height="620" width="500" classid="PathToAssemblyFile.dll#Qualified.Class.Name'
viewastext>
<PARAM NAME="value1" VALUE="<%# dynamicValue %>">
<PARAM NAME="value2" VALUE="thisIsStatic">
</OBJECT>
</form>
</body>
</HTML>
Debugging
Okay, so you wire up your code, place your <Object> tag, and load up the page. Nothing. No error, nothing. You're not going to get a message (unless you dump exception strings to a label in your control). And even if you did, you start debugging aspnet_wp.exe, set some break points in your new control, and still nothing!
Here's the trick. (Sorry if you're not using Visual Studio) Click Tools, Debug Processes, and scroll through the list of processes. Notice the IExplorer with your web page in it. Notice under the 'Types' field. See the .Net there? That's your component! Attach to that, and you will now be able to debug your .Net Applet. Pretty cool, huh!
Parameters
What! This isn't enough? You want to pass parameters to your control? You don't know how to do this? Neither did I. I never really used the Object tag much. But now I am, and passing parameters is easy.
Between your opening and closing <Object> tags place a <Param> tag. Here's an example:
<param name="publicProp" value='yadaYadaYada' />
Not to bad. How about dynamic or programmatic values? Try this:
<param name=" publicProp " value='<%# myYadaValue %>' />
'myYadaValue' is a public property in your web pages code. Easy, right? Now how about values in your Applet, how do you get these? You need to create a public property. You cannot pass to a public variable, be-it string, integer, boolean, or what-not. Has to be a property. So do up your code for a property and you can now access it with Javascript.
HTH