C#

lenovo030130 2010-10-20 07:39:36
我在按课本上的程序写一个窗体应用程序,窗体还没有设计,先设计了一些类,出现以下错误:警告 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;
}
}
}



...全文
204 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
phil999 2010-10-21
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 lenovo030130 的回复:]
我想接着再问一下三楼的哥,我解决的办法是没有拿到别处,不过保存了Form1。cs里面的代码,就没有问题了,我的问题是把这些代码拿别处去,是放到哪里,我是一个新手还请大家多多指教?
[/Quote]

建新的类文件
lenovo030130 2010-10-20
  • 打赏
  • 举报
回复
我想接着再问一下三楼的哥,我解决的办法是没有拿到别处,不过保存了Form1。cs里面的代码,就没有问题了,我的问题是把这些代码拿别处去,是放到哪里,我是一个新手还请大家多多指教?
水哥阿乐 2010-10-20
  • 打赏
  • 举报
回复
窗体类被破坏了当然不能进行可视化设计.
phil999 2010-10-20
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 lenovo030130 的回复:]
三楼的哥,我就是把这些代码写在Form1的代码文件里了,移到单独的文件里是什么意思?
[/Quote]

拿别处去,让 Form1.cs 里只有 form1 的代码
lenovo030130 2010-10-20
  • 打赏
  • 举报
回复
查找帮助文档显示的信息是
该文件内的类不是从可进行可视化设计的类继承,因此 Visual Studio 无法为该文件打开设计器
不知道怎么解决!
继续顶
lenovo030130 2010-10-20
  • 打赏
  • 举报
回复
三楼的哥,我就是把这些代码写在Form1的代码文件里了,移到单独的文件里是什么意思?
phil999 2010-10-20
  • 打赏
  • 举报
回复
是不是把这些类写在 Form1 的代码文件里了?如果是,移到单独的文件里再试

wuyq11 2010-10-20
  • 打赏
  • 举报
回复
Object所有类的最终基类
bai532656789 2010-10-20
  • 打赏
  • 举报
回复
没看明白你是什么意思? 是要自己从无到有的设计一个窗体?

微软不是给方法了么? 哪都可以改啊 这么麻烦干嘛

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧