Form继承的问题
一个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继承其父类的淡入淡出效果?