winform项目中,如何在form中重写自定义datagridview事件?
有一个自定义控件datagridviewEx,继承自datagridview控件,其中有方法A,设置为可重写(virtual),
生成该控件,并把该控件放置在一个form上,现在想重写datagridview的方法A,要如何才能重写?
在form的代码状态下输入override,出来的智能提示只显示了form本身允许重写的事件,
看不到datagridviewEx的方法A,也就无法重写了。
[解决办法]
[解决办法]
- C# code
using System;using System.Windows.Forms;namespace WindowsFormsApplication4{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void myUserControl1_OnMyEvent(string text) { MessageBox.Show(text); } private void myUserControl2_OnMyEvent(string text) { MessageBox.Show(text); } private void button1_Click(object sender, EventArgs e) { myUserControl1.MyEvent("123"); myUserControl2.MyEvent("456"); } } public class MyUserControl : UserControl { public delegate void MyDelegate(String text); public event MyDelegate OnMyEvent; public void MyEvent(String text) { if (OnMyEvent != null) { OnMyEvent(text); } } }}