C# Applet


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'twork 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 orwith apache. BTW http://www.brinkster.com make free ".NET" hosting.

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

After you wrote your customSystem.Windows.Forms.Control, create it with a parameterlessconstructor (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);
}
}

Most Commented Articles :

Twitter Digg Delicious Stumbleupon Technorati Facebook Email

No comments yet... Be the first to leave a reply!