下面一段文字來自C# Expert,
I am wondering how to build a C# applet. I built a class library with a custom control. But the browser (IE6) fails to render it as an object. Do you have some examples to show how to achIEve this? By the way, can a C# applet be run under platforms without the .Net Framework pre-installed?
There's no such concept as a C# "applet". At most, there are custom Windows forms controls that are embedded on a page. Of course, just like in Java, you can't run it if you don't have the corresponding runtime on the clIEnt Machine. You can use the <object> tag to add it to an Html page: (zzj0820注:其實並沒有所謂的C# Applet的概念,通常所說的C# Applet指的是嵌入到浏覽器裡的窗體控件。當然,跟Java類似,必須在客戶端機器上安裝相應的運行時庫才能使用嵌入在Html頁面裡的object標簽控件)
<object id="MyControl" classid="http://mywebsite/MyClassLibrary.dll#FullNamespace.MyControlClass" height="480 "width="640"></object>
The class ID contains the URL of the DLL for downloading and the fully qualifIEd name of the class that implements the control. The library must not be placed on the /bin folder of a Web application in order to be served by IIS/ASP.Net
下面有兩個簡單的例子,希望有所幫助J
Eg1: 原文鏈接
/*
* A simple C# program that displays some text in a webpage.
* Compile with: "csc /t:library hello-world-applet.cs"
* Run byte deploying in a webpage with:
* <object classid="http:hello-world-applet.dll#HelloWorldApplet" width="200" height="100"></object>
* Ben Bederson, January 16, 2002
*/
using System;
using System.Drawing;
using System.Windows.Forms;
public class HelloWorldApplet : System.Windows.Forms.Control {
public HelloWorldApplet() {
// Create a "label" control
Label label = new Label();
label.Text = "Hello world!";
label.ForeColor = Color.Blue;
label.Font = new Font("Arial", 24, FontStyle.Bold);
label.AutoSize = true;
// Insert the label
Controls.Add(label);
}