首页 > 开发 > 综合 > 正文

关于"C# Applet"

2024-07-21 02:18:24
字体:
来源:转载
供稿:网友

商业源码热门下载www.html.org.cn

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

}

}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表