Amazon.com
Amazon.com
coverEssential .NET
Don Box
coverJamsa's C/C++/C# Programmer's Bible
Kris Jamsa
Search C#
Help Board
(8326 Postings)
Search C#
Articles/Code
C# Help Board

Archived Articles
250 Articles

C# Books
Search Site/Articles
What Is C#?
Download Compiler
Code Archive
Advertise
Contribute
C# Jobs
Beginners Tutorial
C# Contractors
Links
C# Manual
Contact Us
Legal
PHP World

cover
C# In 21 Days

cover
Professional C#

cover
C# Unleashed

Inside C#
(With CD-ROM)

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:



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

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


C# Web control I


and now...

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