請教: 繼承問題,請看程式碼!
简叔 2004-01-30 09:15:32
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
class DrawHouse : PrintableForm
{
public new static void Main()
{
Application.Run(new DrawHouse());
}
public DrawHouse()
{
Text = "Draw A House";
}
protected override void DoPage(Graphics grfx,Color color, int cy, int cy)
{
grfx.DrawLines(new Pen(color),
new Point[]{
new Point(cx / 4, 3* cy/4),// Lower left
new Point(cx / 4, cy / 2),
new Point(cx / 2, cy / 2),// Peak
new Point(cx / 4, cy / 2),
new Point(cx/4, 3*cy/4 ),// Lower left
new Point(3*cx/4, 3*cy/4), // Lower right
});
}
}
class PrintableForm : Form
{
public static void Main()
{
Application.Run(new PrintableForm());
}
public PrintableForm()
{
Text = "Printable Form";
ResizeRedraw = true;
}
protected override void OnPaint(PaintEventArgs pea)
{
DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height);
}
protected override void OnClick(EventArgs ea)
{
PrintDocument prndoc = new PrintDocument();
prndoc.DocumentName = Text;
prndoc.PrintPage += new PrintPageEventHandler(PrintDocumentOnPrintPage);
prndoc.Print();
}
void PrintDocumentOnPrintPage(object sender,PrintPageEventArgs ppea)
{
Graphics grfx = ppea.Graphics;
SizeF sizef = grfx.VisibleClipBounds.Size;
DoPage(grfx, Color.Black,(int)sizef.Width, (int)sizef.Height);
}
protected virtual void DoPage(Graphics grfx, Color clr, int cx, int cy)
{
Pen pen = new Pen(clr);
grfx.DrawLine(pen,0,0,cx-1,cy-1);
grfx.DrawLine(pen,cx-1,0,0,cy-1);
}
}
---------- C# Compiler ----------
Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.
DrawHouse.cs(39,24): error CS0017: 程式 'c:\CS\Study C#\DrawHouse.exe' 有一個以上的已定義進入點: 'PrintableForm.Main()'
DrawHouse.cs(12,28): error CS0017: 程式 'c:\CS\Study C#\DrawHouse.exe' 有一個以上的已定義進入點: 'DrawHouse.Main()'
Output completed (0 sec consumed) - Normal Termination