簡體   English   中英

如何從類中訪問事件處理程序以在Form中使用

[英]How to access the event handler from the class to use in the Form

我有一個繼承自DataGridView的類,並且有一個與下面的代碼相同的EventArgs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MyTest
{
    class Test1:System.Windows.Forms.DataGridView
    {
        private void Test1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Click");

        }

    }
}

然后,我有一個表單,我想在表單中使用Test1。 所以我將Test1從Toolbox拖到窗體上。我想要的是,當我運行窗體並單擊Test1時,它將顯示消息“ CellMousClick”,但是當我運行窗體時,它不顯示任何內容。

在Test1類中創建一個構造函數,並附加一個事件處理程序,例如:

public Test1()
{
  this.CellMouseClick += new DataGridViewCellMouseEventHandler(this.Test1_Click);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM