网页功能: 加入收藏 设为首页 网站搜索  
关于实现日志的明细保存问题
发表日期:2005-05-29作者:dtqgfnet[转贴] 出处:CSDN  

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

 

我来说两句】 【加入收藏】 【返加顶部】 【打印本页】 【关闭窗口
中搜索 关于实现日志的明细保存问题
本类热点文章
  简单的多人聊天(C#.Socket)
  C#的office操作[word&Excel]
  在C#中调用VBScript、JavaScript等脚本..
  在C#中调用VBScript、JavaScript等脚本..
  C#程序编码规范
  C#程序编码规范
  使用c#获得cpu,硬盘的序列号
  在Linux上运行C#
  在Linux上运行C#
  弹出窗口杀手
  弹出窗口杀手
  算术表达式解析器的实现思路
最新分类信息我要发布 
最新招聘信息

关于我们 / 合作推广 / 给我留言 / 版权举报 / 意见建议 / 广告投放  
Copyright ©2003-2024 Lihuasoft.net webmaster(at)lihuasoft.net
网站编程QQ群   京ICP备05001064号 页面生成时间:0.00425