事件的处理

EventArgs.cs

using System;
using System.Collections.Generic;
using System.Text;

using XML;

namespace CommonToolkit.Controls.Common {
    public class BatchEventArgs : EventArgs {
        public Batch Batch;

        public BatchEventArgs(Batch batch) {
            this.Batch = batch;
        }
    }

    public class DocumentEventArgs : EventArgs {
        public Document Document;

        public DocumentEventArgs(Document document) {
            this.Document = document;
        }
    }

    public class FolderEventArgs : EventArgs {
        public Folder Folder;

        public FolderEventArgs(Folder folder) {
            this.Folder = folder;
        }
    }

    public class PageEventArgs : EventArgs {
        public Page Page;
        public Document Document;

        public PageEventArgs(Page page,Document document) {
            this.Page = page;
            this.Document = document;
        }
    }

    public class NodeEventArgs : EventArgs {
        public Folder Folder;
        public Document Document;

        public NodeEventArgs(Folder folder) {
            this.Folder = folder;
        }
        public NodeEventArgs(Document document) {
            this.Document = document;
        }
    }
}

*********************************************************************

Delegate.cs

using System;
using System.Collections.Generic;
using System.Text;

namespace CommonToolkit.Controls.Common {
    public delegate void BatchClickEventHandler(object sender, BatchEventArgs e);
    public delegate void FolderClickEventHandler(object sender, FolderEventArgs e);
    public delegate void DocumentClickEventHandler(object sender, DocumentEventArgs e);
    public delegate void PageClickEventHandler(object sender, PageEventArgs e);
    public delegate void SwitchNodeEventHandler(object sender,NodeEventArgs e);
}

*********************************************************************

CustTreeView.cs

using System.Text;
using System.Collections;
using System.Windows.Forms;

using XML;

using CommonToolkit.Controls.Common;

namespace CommonToolkit.Controls {
    public partial class CustTreeView : TreeView {

        public event BatchClickEventHandler BatchClick;
        public event FolderClickEventHandler FolderClick;
        public event DocumentClickEventHandler DocumentClick;
        public event PageClickEventHandler PageClick;
        public event SwitchNodeEventHandler SwitchNode;

        public CustTreeView() {
            InitializeComponent();
        }

        //定义一个具有与事件委托相同的签名的事件处理程序方法。
        public virtual void OnBatchClick(object sender, BatchEventArgs args) {
            if (BatchClick != null) {
                BatchClick(sender, args);
            }
        }
        public virtual void OnFolderClick(object sender, FolderEventArgs args) {
            if (FolderClick != null) {
                FolderClick(sender, args);
            }
        }
        public virtual void OnDocumentClick(object sender, DocumentEventArgs args) {
            if (DocumentClick != null) {
                DocumentClick(sender, args);
            }
        }
        public virtual void OnPageClick(object sender, PageEventArgs args) {
            if (PageClick != null) {
                PageClick(sender, args);
            }
        }
    }
}

*********************************************************************

frmTreeView.Designer.cs

            //将该委托实例添加到事件

            this.ctrvBatch.PageClick += new CommonToolkit.Controls.Common.PageClickEventHandler(this.ctrvBatch_PageClick);
            this.ctrvBatch.DocumentClick += new CommonToolkit.Controls.Common.DocumentClickEventHandler(this.ctrvBatch_DocumentClick);
            this.ctrvBatch.BatchClick += new CommonToolkit.Controls.Common.BatchClickEventHandler(this.ctrvBatch_BatchClick);
            this.ctrvBatch.FolderClick += new CommonToolkit.Controls.Common.FolderClickEventHandler(this.ctrvBatch_FolderClick);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值