如果您想让某个对象能够响应事件,就要在声明它时使用WithEvent关键字(WithEvents 关键字指示被声明的对象变量引用可以引发事件的类实例)。例如,当您想让按钮(button)能够响应事件,就要将声明:Private Button1 As Button替换为:Private WithEvents Button1 As Button在c#中显然不需要这样定义。
public class1 ClassInst即可

解决方案 »

  1.   

    Public  ------ public
    WithEvents ----- 不管
    ClassInst As Class1 ----- Class1 ClassInst
    public Class1 ClassInst
      

  2.   

    public class1 ClassInst
    如果有事件你可以用
    ClassInst.事件名+=new 事件代理(你的处理事件的方法)
      

  3.   

    luoqing(明天将会...)
    谢谢,这一点我明白了;
    可是
    ClassInst.事件名+=new 事件代理(你的处理事件的方法)
    应该在什么地方调用呢?我这个地方一直调试不过去,唉
      

  4.   

    private void InitializeComponent()
    {    
    this.Load += new System.EventHandler(this.Page_Load);
    }
    事件的代理都是在InitializeComponent()的方法里
      

  5.   

    如果在InitializeComponent()内加的话,当你在设计时修改窗体及窗体内的属时,IDE会自动把你加入的代码删除
      

  6.   

    luoqing(明天将会...) 
    我找不到错误!
    前面在主窗体中设置好了dataview   dvmyTreeView myTree;
    myTree.DataSource=tv;************下面是重写控件的代码using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Windows.Forms;namespace myControls
    {#region 1 继承的类TreeViewpublic class myTreeView : System.Windows.Forms.TreeView
    {
       public static System.Windows.Forms.CurrencyManager cm;
       private object m_DataSource;
       public myTreeView():base()
       {
    InitializeComponent();
       }
    //////////////////
      protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
       }/////////////////
    private System.ComponentModel.Container components = null;
    private void InitializeComponent()
    {
    components = new System.ComponentModel.Container();
    }//////////////public object DataSource
    {

       get   {
          return m_DataSource;
       }
       set
       {
          if(value is IListSource)
          {
              m_DataSource=value;
              cm=(CurrencyManager)                     this.BindingContextvalue[value];
    *********************在这里报错!!!!
              
          }
       }
      

  7.   

    没有this.BindingContextvalue这个属性
      

  8.   

    是我写错了
    原来写的是this.BindingContext[value];
    也是不对的