关于实现日志的明细保存问题

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

关于实现日志的明细保存问题

2005-05-24 与联想桥

思路:

通过一个自定义控件和全局变量实现对每一步进行详细的日志记录

通BOTTON的委托关系实现调用自定义控件外部BOTTON的单击事件

下面是一个非常简单的例子,

-----自定义控件

using System;

using System.Collections;

using System.ComponentModel;

using System.Drawing;

using System.Data;

using System.Windows.Forms;

namespace ZCGL.BaseClass

{

/// <summary>

/// bt

/// 一个BUTTON按钮

/// </summary>

public class bt : System.Windows.Forms.UserControl

{

public System.Windows.Forms.Button btC;

/// <summary>

/// 必需的设计器变量。

/// </summary>

private System.ComponentModel.Container components = null;

public bt()

{

// 该调用是 Windows.Forms 窗体设计器所必需的。

InitializeComponent();

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

}

/// <summary>

/// 清理所有正在使用的资源。

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if(components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region 组件设计器生成的代码

/// <summary>

/// 设计器支持所需的方法 - 不要使用代码编辑器

/// 修改此方法的内容。

/// </summary>

private void InitializeComponent()

{

this.btC = new System.Windows.Forms.Button();

this.SuspendLayout();

//

// btC

//

this.btC.Location = new System.Drawing.Point(0, 0);

this.btC.Name = "btC";

this.btC.Size = new System.Drawing.Size(72, 24);

this.btC.TabIndex = 0;

this.btC.Click += new System.EventHandler(this.btC_Click);

//

// bt

//

this.Controls.Add(this.btC);

this.Name = "bt";

this.Size = new System.Drawing.Size(72, 24);

this.ResumeLayout(false);

}

#endregion

内部单击事件代码

private void btC_Click(object sender, System.EventArgs e)

{

MessageBox.Show("内部BOTTON");

}

实现动态的BOTTON名称

public string BtName

{

get

{

return this.btC.Text;

}

set

{

this.btC.Text = value;

}

}

}

-----继承后的代码

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

namespace BaseClass

{

/// <summary>

/// Form1 的摘要说明。

/// </summary>

public class Form1 : System.Windows.Forms.Form

{

private System.Windows.Forms.Label label1;

private ZCGL.BaseClass.bt bt1;

/// <summary>

/// 必需的设计器变量。

/// </summary>

private System.ComponentModel.Container components = null;

public Form1()

{

//

// Windows 窗体设计器支持所必需的

//

InitializeComponent();

//

// TODO: 在 InitializeComponent 调用后添加任何构造函数代码

//

}

/// <summary>

/// 清理所有正在使用的资源。

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region Windows 窗体设计器生成的代码

/// <summary>

/// 设计器支持所需的方法 - 不要使用代码编辑器修改

/// 此方法的内容。

/// </summary>

private void InitializeComponent()

{

this.label1 = new System.Windows.Forms.Label();

this.bt1 = new ZCGL.BaseClass.bt();

this.SuspendLayout();

//

// label1

//

this.label1.Location = new System.Drawing.Point(48, 56);

this.label1.Name = "label1";

this.label1.Size = new System.Drawing.Size(208, 104);

this.label1.TabIndex = 0;

this.label1.Text = "基础类库";

//

// bt1

//

this.bt1.BtName = "显示";

this.bt1.Location = new System.Drawing.Point(72, 176);

this.bt1.Name = "bt1";

this.bt1.Size = new System.Drawing.Size(72, 24);

this.bt1.TabIndex = 1;

this.bt1.Load += new System.EventHandler(this.bt1_Load);

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);

this.ClientSize = new System.Drawing.Size(292, 273);

this.Controls.Add(this.bt1);

this.Controls.Add(this.label1);

this.Name = "Form1";

this.Text = "Form1";

this.ResumeLayout(false);

}

#endregion

private void bt1_Load(object sender, System.EventArgs e)

{

//增加委托实现调用外部的事件

this.bt1.btC.Click += new System.EventHandler(this.bt_Click);

}

外部事件

private void bt_Click(object sender, System.EventArgs e)

{

MessageBox.Show("外部BOTTON");

}

/// <summary>

/// 应用程序的主入口点。

/// </summary>

[STAThread]

static void Main()

{

Application.Run(new Form1());

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航