程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> 關於“C# Applet”

關於“C# Applet”

編輯:.NET實例教程
下面一段文字來自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);

}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved