C#
我在按课本上的程序写一个窗体应用程序,窗体还没有设计,先设计了一些类,出现以下错误:警告 1 文件中的类都不能进行设计,因此未能为该文件显示设计器。设计器检查出文件中有以下类:
Shape --- 无法设计基类“System.Object”。
MyLine --- 无法加载基类“DrawGraphic.Shape”。请确保已引用该程序集并已生成所有项目。
MyRectangle --- 无法加载基类“DrawGraphic.Shape”。请确保已引用该程序集并已生成所有项目。
MyFilledRectangle --- 无法加载基类“DrawGraphic.Shape”。请确保已引用该程序集并已生成所有项目。
MyEllipse --- 无法加载基类“DrawGraphic.MyRectangle”。请确保已引用该程序集并已生成所有项目。
MyFilledEllipse --- 无法加载基类“DrawGraphic.MyRectangle”。请确保已引用该程序集并已生成所有项目。
MyCircleRect --- 无法加载基类“DrawGraphic.MyRectangle”。请确保已引用该程序集并已生成所有项目。
ShapeFactory --- 无法设计基类“System.Object”。
Form1 --- 无法设计基类“System.Object”。 0 0
不知道这是怎么一回事,现在也无法设计窗体!求助,
以下是代码:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
namespace DrawGraphic
{
public abstract class Shape
{
private Point first;//图形起始点
public Point First
{
set { this.first = value; }
get { return this.first; }
}
private Point last;//图形终点
public Point Last
{
set { this.last = value; }
get { return this.last; }
}
private Color foreColor;//图形颜色
public Color ForeColor
{
set { this.foreColor = value; }
get { return this.foreColor; }
}
private int penWidth;//图形线宽
public int PenWidth
{
set { this.penWidth = value; }
get { return this.penWidth; }
}
public Shape()//父类构造器,是不是可以省略?
{ }
public abstract void Draw(Graphics grfx);//定义抽象类
}
public class MyLine : Shape//画直线
{
public override void Draw(Graphics grfx)
{
Pen p = new Pen(ForeColor, PenWidth);
grfx.DrawLine(p, First, Last);
}
}
public class MyRectangle : Shape//画矩形
{
protected int left;
protected int top;
protected int width;
protected int height;
protected void SetParams() //定义2个点,宽和高
{
left = First.X > Last.X ? Last.X : First.X;
top = First.Y > Last.Y ? Last.Y : First.Y;
width = Math.Abs(Last.X - First.X);
height = Math.Abs(Last.Y - First.Y);
}
public override void Draw(Graphics grfx)
{
SetParams();
Pen p = new Pen(ForeColor, PenWidth);
grfx.DrawRectangle(p, left, top, width, height);
}
}
public class MyFilledRectangle : Shape //画填充矩形
{
protected int left;
protected int top;
protected int width;
protected int height;
protected void SetParams()
{
left = First.X > Last.X ? Last.X : First.X;
top = First.Y > Last.Y ? Last.Y : First.Y;
width = Math.Abs(Last.X - First.X);
height = Math.Abs(Last.Y - First.Y);
}
public override void Draw(Graphics grfx)
{
SetParams();
Brush b = new SolidBrush(ForeColor);
grfx.FillRectangle(b, left, top, width, height);
}
}
public class MyEllipse : MyRectangle //画椭圆
{
public override void Draw(Graphics grfx)
{
SetParams();
Pen p = new Pen(ForeColor, PenWidth);
grfx.DrawEllipse(p, left, top, width, height);
}
}
public class MyFilledEllipse : MyRectangle //画填充椭圆
{
public override void Draw(Graphics grfx)
{
SetParams();
Brush b = new SolidBrush(ForeColor);
grfx.FillEllipse(b, left, top, width, height);
}
}
public class MyCircleRect : MyRectangle
{
public override void Draw(Graphics grfx)
{
SetParams();
Pen p = new Pen(ForeColor, PenWidth);
grfx.DrawLine(p, new Point(left + 10, top), new Point(left + width - 10, top));
grfx.DrawLine(p, new Point(left + width, top + 10), new Point(left + width, top + height - 10));
grfx.DrawLine(p, new Point(left + width - 10, top + height), new Point(left + 10, top + height));
grfx.DrawLine(p, new Point(left, top + height - 10), new Point(left, top + 10));
grfx.DrawArc(p, left, top, 20, 20, 180, 90);
grfx.DrawArc(p, left + width - 20, top, 20, 20, 0, -90);
grfx.DrawArc(p, left + width - 20, top + height - 20, 20, 20, 0, 90);
grfx.DrawArc(p, left, top + height - 20, 20, 20, 90, 90);
}
}
public enum ShapeType //定义图形类型
{
Line,
Rect,
Ellipse,
CircleRect,
FilledRect,
FilleEllipse
}
public class ShapeFactory
{
public static Shape CreateShape(ShapeType type)
{
Shape shape = null;
switch (type)
{
case ShapeType.Line://画直线
shape = new MyLine();
break;
case ShapeType.Rect://画矩形
shape = new MyRectangle();
break;
case ShapeType.Ellipse://画椭圆
shape = new MyEllipse();
break;
case ShapeType.CircleRect://画圆角矩形
shape = new MyCircleRect();
break;
case ShapeType.FilledRect://画填充矩形
shape = new MyFilledRectangle();
break;
case ShapeType.FilleEllipse://画填充椭圆
shape = new MyFilledEllipse();
break;
}
return shape;
}
}
}