winform窗体的继承问题

willisway 2006-10-27 09:38:15
usre _user_information
public Form_information(user user_info)
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
_user_buginfo = user_info;

}
现在我要添加一个继承于此窗体的窗体,为什么继承不成功呢?1、在“解决方案管理器”中“添加继承窗体”(继承后的错误信息为: 试图创建 bugmanage.Form_buginfo 的实例时发生异常。异常为“未找到类型 bugmanage.Form_buginfo 上的构造函数。”。)2、这样继承public class Form2 : Form_information也不行,提示说(“Form_information” : 接口列表中的类型不是接口.)是不是因为父窗体中有个类?那怎么继承呢?谢谢大家,帮帮忙
...全文
842 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
willisway 2006-11-02
  • 打赏
  • 举报
回复
运行的时候继承窗体能够出现,但是作窗体设计的时候不能出现,所以继承后的窗体就无法改变了,那继承过来就没意义了,唉,没办法啊
willisway 2006-11-01
  • 打赏
  • 举报
回复
我已经放弃了,还是搞不定,不知道出了什么问题,谢谢大家
zCheng 2006-10-31
  • 打赏
  • 举报
回复
不大明白……是不是有命名冲突……
要不你把参数名称改变一下,比如改为 _user_info;然后把 this. 删除
willisway 2006-10-30
  • 打赏
  • 举报
回复
user是一个类名
谢谢zCheng(NullRefrenceException) 的帮助,可是我按你的方法添加以后,提示说:“非静态的字段、方法或属性“user_info”要求对象引用”, “文件中的类都不能进行设计,因此未能为该文件显示设计器。设计器检查出文件中有以下类:Form2 --- 未能加载基类“Form1”。如果程序集是项目的一部分,请确保它已被引用或生成。”

anuo06 2006-10-28
  • 打赏
  • 举报
回复
usre _user_information
这是个什么东西
zCheng 2006-10-28
  • 打赏
  • 举报
回复
示例代码:
public class Form1 : Form
{
private User user_info;
public Form1() // 提供一个不带参数的构造函数
{
InitializeComponents();
this.user_info = null;
}
public Form1(User user_info)
{
InitializeComponents();
this.user_info = user_info;
}
// ...
}

public class Form2 : Form1
{
public Form2() : base() // 提供无参数的构造函数
{
this.InitializeComponents();
// Do your things here.
}
public Form2(User user_info) : base(user_info)
{
this.InitializeComponents();
// Do your things here.
}
}

这样应该就可以了。
JasonHeung 2006-10-28
  • 打赏
  • 举报
回复
基类写一个无参数构造函数

public Form_information() : this(null)
{


}
zCheng 2006-10-28
  • 打赏
  • 举报
回复
出现异常是因为,你的基窗体只有一个带参数的构造函数,而系统构造窗体设计器时会调用窗体的无参数的构造函数,所以会导致继承失败。

解决的方法就是在你原来的窗体添加一个默认的构造函数。

public Form_information(user user_info)
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
_user_buginfo = user_info;

}
public Form_information() // 添加一个新的,无参数的构造函数
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
_user_buginfo = null;

}
股神 2006-10-28
  • 打赏
  • 举报
回复
up
lizhizhe2000 2006-10-28
  • 打赏
  • 举报
回复
继承应许不是太难,只是你给的信息难以判断!

110,534

社区成员

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

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

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