.NET开发

本类阅读TOP10

·NHibernate快速指南(翻译)
·vs.net 2005中文版下载地址收藏
·【小技巧】一个判断session是否过期的小技巧
·VB/ASP 调用 SQL Server 的存储过程
·?dos下编译.net程序找不到csc.exe文件
·通过Web Services上传和下载文件
·学习笔记(补)《.NET框架程序设计(修订版)》--目录
·VB.NET实现DirectDraw9 (2) 动画
·VB.NET实现DirectDraw9 (1) 托管的DDraw
·建站框架规范书之——文件命名

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
关于实现日志的明细保存问题

作者:未知 来源:月光软件站 加入时间:2005-6-5 月光软件站

关于实现日志的明细保存问题
 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());
  }




相关文章

相关软件