Form继承的问题

pimple 2003-05-20 09:10:30
一个frmFadeFormSon继承了frmFadeForm,以实现淡入淡出效果。

//frmFadeForm(父类)

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;

using System.Windows.Forms;


namespace WindowsApplication1
{
public class frmFadeForm : Form
{
private bool isFadein;
private bool isCloseing;
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components = null;

public frmFadeForm()
{
// 该调用是 Windows 窗体设计器所必需的。
InitializeComponent();

// TODO: 在 InitializeComponent 调用后添加任何初始化
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
//
// timer1
//
this.timer1.Interval = 50;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// frmFadeForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(400, 301);
this.MinimumSize = new System.Drawing.Size(50, 50);
this.Name = "frmFadeForm";
this.Opacity = 0;
this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
this.Load += new System.EventHandler(this.Form1_Load);

}
#endregion

private void Form1_Load(object sender, System.EventArgs e)
{
Fadein();
}

private void timer1_Tick(object sender, System.EventArgs e)
{
if (isFadein)
{
this.Opacity += 0.1;
if (this.Opacity == 1)
this.timer1.Stop();
}
else
{
this.Opacity -= 0.1;
if (this.Opacity == 0)
{
this.timer1.Stop();
isCloseing = true;
this.Close();
}
}
}
private void Fadein()
{
isFadein = true;
this.timer1.Start();
}
private void Fadeout()
{
isFadein = false;
this.timer1.Start();
}

private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (!isCloseing)
{
e.Cancel = true;
Fadeout();
}
}

}
}

//frmFadeFormSon(子类)

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;

using System.Windows.Forms;


namespace WindowsApplication1
{
public class frmFadeFormSon : WindowsApplication1.frmFadeForm
{
private System.Windows.Forms.Label label1;
private System.ComponentModel.IContainer components = null;

public frmFadeFormSon()
{
// 该调用是 Windows 窗体设计器所必需的。
InitializeComponent();

// TODO: 在 InitializeComponent 调用后添加任何初始化
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.Location = new System.Drawing.Point(24, 128);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(352, 23);
this.label1.TabIndex = 0;
this.label1.Text = "label1";
//
// frmFadeFormSon
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(400, 301);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label1});
this.Name = "frmFadeFormSon";
this.Opacity = 1;
this.Load += new System.EventHandler(this.frmFadeFormSon_Load);
this.ResumeLayout(false);

}
#endregion

private void frmFadeFormSon_Load(object sender, System.EventArgs e)
{
this.label1.Text = "This form inherite from frmFadeForm!";
//base.OnLoad(e);
}
}
}


问题:
在frmFadeFormSon(子类)中使用了Load事件,为什么frmFadeForm(父类)的Load事件就不执行了?

如果我用base.OnLoad(e)来调用父类的Load事件,系统抛出异常:

未处理的“System.StackOverflowException”类型的异常出现在 system.windows.forms.dll 中

怎么才能让frmFadeFormSon继承其父类的淡入淡出效果?
...全文
75 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
pimple 2003-05-21
  • 打赏
  • 举报
回复
不行

继续等待...
henryfan1 2003-05-21
  • 打赏
  • 举报
回复
public frmFadeFormSon():base()
{

}
构造函数改成这样试下
pimple 2003-05-21
  • 打赏
  • 举报
回复
表单的效果是次要,我主要想弄明白父类的OnLoad事件没有执行吗?
pimple 2003-05-21
  • 打赏
  • 举报
回复
在OnLoad事件中用base.OnLoad(e)来调用父类的Load事件,系统抛出异常:

未处理的“System.StackOverflowException”类型的异常出现在 system.windows.forms.dll 中

怎么能才调用父类的OnLoad事件?
tjq_tang 2003-05-20
  • 打赏
  • 举报
回复
http://wlbookwl.myrice.com/jck/1027apidc.htm
是使用API写的.但是是vb写的.如果没有办法了,可以参考参考
zhuohs 2003-05-20
  • 打赏
  • 举报
回复



我怎么看到你把load事件写在继承的窗体上了?
看代码好累!

zhuohs 2003-05-20
  • 打赏
  • 举报
回复


Your code is too long !

110,568

社区成员

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

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

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