.NET开发

本类阅读TOP10

·NHibernate快速指南(翻译)
·vs.net 2005中文版下载地址收藏
·【小技巧】一个判断session是否过期的小技巧
·VB/ASP 调用 SQL Server 的存储过程
·?dos下编译.net程序找不到csc.exe文件
·通过Web Services上传和下载文件
·学习笔记(补)《.NET框架程序设计(修订版)》--目录
·VB.NET实现DirectDraw9 (2) 动画
·VB.NET实现DirectDraw9 (1) 托管的DDraw
·建站框架规范书之——文件命名

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
关于“C# Applet”

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

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

    }

}




相关文章

相关软件