Search Forum
(53671 Postings)
Search Site/Articles

Archived Articles
712 Articles

C# Books
C# Consultants
What Is C#?
Download Compiler
Code Archive
Archived Articles
Advertise
Contribute
C# Jobs
Beginners Tutorial
C# Contractors
C# Consulting
Links
C# Manual
Contact Us
Legal

GoDiagram for .NET from Northwoods Software www.nwoods.com


 
Printable Version

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);
    }
}