WithEvents

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Water Cooler v2

    #1

    WithEvents

    Am I right in guessing that there is no direct C# equivalant for the
    'WithEvents' VB keyword. The substitute is to add event handlers to the
    delegate instances that are the public members of the class.

    For instance,

    Public WithEvents ObjFoo As New ClassFoo

    Public Sub ObjFoo_FooDone( ByVal sender as Object, ByVal e As EventArgs)
    Console.WriteLi ne("Foo has been done.")
    End Sub



    public ClassFoo ObjFoo;

    public void Init()
    {
    ObjFoo = new ClassFoo();
    ObjFoo.FooDone += new TheClassOfWhich FooDoneIsAType( fooDone);
    }


    public void fooDone(Object s, EventArgs e)
    {
    Console.WriteLi ne("Foo has been done.");
    }

  • Peter Bromberg [C# MVP]

    #2
    RE: WithEvents

    Water Cooler,
    You are correct. And it's been beaten to death, if you search the group.
    Peter

    --
    Co-founder, Eggheadcafe.com developer portal:

    UnBlog:





    "Water Cooler v2" wrote:
    Am I right in guessing that there is no direct C# equivalant for the
    'WithEvents' VB keyword. The substitute is to add event handlers to the
    delegate instances that are the public members of the class.
    >
    For instance,
    >
    Public WithEvents ObjFoo As New ClassFoo
    >
    Public Sub ObjFoo_FooDone( ByVal sender as Object, ByVal e As EventArgs)
    Console.WriteLi ne("Foo has been done.")
    End Sub
    >
    >
    >
    public ClassFoo ObjFoo;
    >
    public void Init()
    {
    ObjFoo = new ClassFoo();
    ObjFoo.FooDone += new TheClassOfWhich FooDoneIsAType( fooDone);
    }
    >
    >
    public void fooDone(Object s, EventArgs e)
    {
    Console.WriteLi ne("Foo has been done.");
    }
    >
    >

    Comment

    • Water Cooler v2

      #3
      Re: WithEvents

      Peter wrote:
      Water Cooler,
      You are correct. And it's been beaten to death, if you search the group.
      Peter

      Thank you, Peter.

      Comment

      • Adam Clauss

        #4
        Re: WithEvents

        WithEvents?

        I've never even heard of it... I'm gonna have to go dig this up.

        -Adam



        "Peter Bromberg [C# MVP]" <pbromberg@yaho o.nospammin.com wrote in message
        news:03DCE61A-D187-4BF0-947B-9A3879314800@mi crosoft.com...
        Water Cooler,
        You are correct. And it's been beaten to death, if you search the group.
        Peter
        >
        --
        Co-founder, Eggheadcafe.com developer portal:

        UnBlog:

        >
        >
        >
        >
        "Water Cooler v2" wrote:
        >
        >Am I right in guessing that there is no direct C# equivalant for the
        >'WithEvents' VB keyword. The substitute is to add event handlers to the
        >delegate instances that are the public members of the class.
        >>
        >For instance,
        >>
        >Public WithEvents ObjFoo As New ClassFoo
        >>
        >Public Sub ObjFoo_FooDone( ByVal sender as Object, ByVal e As EventArgs)
        > Console.WriteLi ne("Foo has been done.")
        >End Sub
        >>
        >>
        >>
        >public ClassFoo ObjFoo;
        >>
        >public void Init()
        >{
        >ObjFoo = new ClassFoo();
        >ObjFoo.FooDo ne += new TheClassOfWhich FooDoneIsAType( fooDone);
        >}
        >>
        >>
        >public void fooDone(Object s, EventArgs e)
        >{
        >Console.WriteL ine("Foo has been done.");
        >}
        >>
        >>

        Comment

        • Wamba

          #5
          Re: WithEvents


          Adam Clauss wrote:
          WithEvents?
          >
          Yes, in Vb.net you need to declare a class with this attribute if u
          like to work with events.

          Comment

          • Branco Medeiros

            #6
            Re: WithEvents


            Wamba wrote:
            Adam Clauss wrote:
            WithEvents?
            Yes, in Vb.net you need to declare a class with this attribute if u
            like to work with events.
            Well, you don't *need*, it's a feature. If you don't want to use
            WithEvents, you may allways explicitly add your event handlers, if
            you're so inclined, just like the example in C#.

            Regards,

            Branco.

            Comment

            • Michael D. Ober

              #7
              Re: WithEvents

              Sometime's it's useful to declare the class object "withevents " to let the
              IDE assist in the event syntax. Other times, use the AddHandler method for
              more control over when an event becomes eligible for firing.

              Mike Ober.

              "Branco Medeiros" <branco.medeiro s@gmail.comwrot e in message
              news:1152633389 .470627.325600@ s13g2000cwa.goo glegroups.com.. .
              >
              Wamba wrote:
              Adam Clauss wrote:
              WithEvents?
              >
              Yes, in Vb.net you need to declare a class with this attribute if u
              like to work with events.
              >
              Well, you don't *need*, it's a feature. If you don't want to use
              WithEvents, you may allways explicitly add your event handlers, if
              you're so inclined, just like the example in C#.
              >
              Regards,
              >
              Branco.
              >

              Comment

              Working...