关于“C# Applet”

下面一段文字来自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);

}

}

Eg2: 原文链接

C# Applet
By Lloyd Dupont

I want to tell you how to write C# Applet, display it in a web page and the requirement.

The requirement first, your C# Applet won't work anywhere nor from anywhere. You should put (and test) it on IIS, for unknown reason (at last unknown to me) this won't work locally or with apache. BTW http://www.brinkster.com make free ".NET" hosting.

Not any client could display a C# Applet, you surely need IE6 and probably .NET SDK (at last with these configuration this work everywhere i know).

After you wrote your custom System.Windows.Forms.Control, create it with a parameterless constructor (which will be called by IE) and wrap it in an assembly.

After you could display it very easily in a web page like this:

<object

id=anID

classid="http:myAssemblyDll.dll#controlClassToInstantiate"

height=300 width=300>

</object>

and with id you could call it public method vis javascript like this

<script> <!--

myID.AProperty = aValue;

myID.Refresh()

//--></script>

Here is an example you could see at http://www24.brinkster.com/superlloyd/un.htm

-- un.html --

<html>

<head>

<title>C# Web control I</title>

</head>

<body>

and now...<br>

<object id=t

classid="http:Un.DLL#WT.T"

height=300 width=300 VIEWASTEXT>

</object>

<br>

<a href=un.cs>source</a>

</body>

</html>

-- un.cs --

using System;

using System.Drawing;

using System.Windows.Forms;

// csc un.cs

// csc /t:library /out:Un.DLL un.cs

namespace WT

{

public class T : Control

{

protected override void OnPaint(PaintEventArgs e)

{

e.Graphics.FillRectangle(new SolidBrush(Color.Azure), ClientRectangle);

e.Graphics.DrawLine(Pens.DarkSalmon,

new Point(0, 0),

new Point(ClientRectangle.Width, ClientRectangle.Height));

}

public static void Main(string[] m)

{

Form f = new Form();

T t = new T();

t.Dock = DockStyle.Fill;

f.Controls.Add(t);

Application.Run(f);

}

}

时间: 2024-11-03 12:07:30

关于“C# Applet”的相关文章

applet-java Applet中param参数存放的值可以放加密过的密码么

问题描述 java Applet中param参数存放的值可以放加密过的密码么 java Applet中param参数存放的值可以放加密过的密码么?这些param值是存在Cookie中么? 解决方案 当然可以 只要服务器端能够正确解析解密还原数据

Applet数字签名,授予访问本地资源

访问 本文章介绍Applet数字签名,授予访问本地资源的方法.步骤一:将Applet Class打成Jar包 如:在命令行中执行以下的语句: jar -cvf MyApplet.jar class 步骤二:(在网页中嵌入Applet)(如何在Html嵌入Apple方法见附录) 下面是嵌入Applet部分的写法: <APPLETCODEBASE = "."CODE = "jcomponent.FileReaderApplet.class"ARCHIVE =&qu

一个经典的JAVA APPLET时钟程序(一)

程序   转眼间一年又要过了,自己又老了一岁,郁闷啊.趁着还有几分钟才新年,赶快再发几篇文章,给过去的一年添点东西. 该程序是从网上发现的,是一个简单的时钟显示程序. 代码特色:时钟代码提供了各种接口,可以在HTML文件中设置,变化出多姿多彩的时钟模型,参数说明见代码内info数组 时钟的绘制采用双缓冲图形处理机制,即先在缓冲区内绘制图形,再把图形显示到网页上可以有效的防止闪烁. 另外时钟的不断绘制是通过一个线程不断读取系统时间,如果时间有变化即绘制.采用一个线程绘制,一个线程处理网页比较符合A

求出e=1+1/1!+1/2!+1/3!+……+1/n!+……的近似值的java applet程序

程序 //求出e=1+1/1!+1/2!+1/3!+--+1/n!+--的近似值,要求误差小于0.0001import java.applet.*;import java.awt.*;import java.awt.event.*;public class AT1_1 extends Applet implements ActionListener{  TextField text1; Button Button1;  public void init() {  text1 = new Text

关于Html嵌入打成jar包的Applet方法

关于Html嵌入Applet的问题标签的属性介绍属性    含义Width    Applet在Html页面上的宽度Height    Applet在Html页面上的高度Name    Applet在Html页面上的名称,用于区名一个Html页面上的多个AppletCode    Applet类名,必须带后缀"class"当没有属性archive时,直接写类名当有属性archive时,必须带包名Codebase    Applet的类相对路径,相对于Html页面位置Archive   

使用jdom操作xml数据,生成含Jtree的applet

dom|xml|数据 转自:http://www.softhouse.com.cn/html/200410/2004102517145700001335.html 使用jdom操作xml数据,生成含Jtree的applet    在我们工作中,常常会碰到树形组件的生成问题,如果你在开发web application,纯粹使用javascript来生成树形组件是非常繁琐的,而且交互性也不不太好.所以许多产品使applet来实现树形组件的功能.比如说,weblogic,jboss等产品的consol

在J2EE中APPLET和HTML作为客户端的比较

j2ee|比较|客户端 前言 在j2ee中,客户端常用的两中方式是html,和基于application的applet,因为采用的技术不同,这两个方式都有其优缺点,在考虑采用何种技术(或者两种都用),需要根据两种技术的特点,以及此项目的应用范围来综合考虑.以下分"易用性","性能","维护,扩展","交互","安全"五部分来说明各自的特点,并针对客户,开发人员角色阐明一下个人观点. 易用性 客户对于易用性要

jsp页面调用applet实现人民币的大小写转换

js|大小写|人民币|页面|转换 实现方法一 applet实现页面是rmb.jsp,此页面是通过applet来实现人民币小写转换成大写的.此页面有三个变量需要在载入classes的时候进行初始化: <applet type="applet" id="myApplet" codebase = "." name="TestApplet" align="middle" code="lqh.rmb.

js与applet的相互调用

js js调用java 可以在网页里使用 <script language=javascript> document.applets[0].java中的方法名 </script> 可以对applet进行控制,也可以从applet返回值. 返回值无需关心值得类型,js会隐式的转换. 传值到applet中应考虑类型匹配. java调用js 需要导入netscape.javascript.jsobject这个类 比如: JSObject window=JSObject.getWindow

Java、Java Applet与 &amp;#106avascript间的通信

摘 要:本文着重阐述了网页开发中,通过灵活使用从JavaScript语言中访问Java的方法.从JavaScript中访问JavaScript小程序的方法与变量,以及在Java Applet小程序中使用JavaScript等技术,实现这几种网页开发语言的互相补充,以开发更完美的Web应用程序. JavaScript是用于HTML环境的开发语言,提供了能够响应Web页面事件的脚本,可以完全访问浏览器窗口的各个方面,善于合并HTML.Java Applet小程序.插入件.服务器方程序和其他Web组件