Results 1 to 10 of 10

Thread: Events in C#, and Me from VB.NET

  1. #1

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Events in C#, and Me from VB.NET

    In VB.NET, you could go into the code view of a form and select which event you want to use for any object and it would insert the code for the function. In C#, it lists the members and it's functions/variables. While this is useful, how exactly do I use events? Do I have to guess at what they're called or something?

    Also, in VB.NET I could use the Me namespace to do alot of different things. What would be the alternative to Me in C#? Or isn't their one?

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    i really think u should pick up a c# book
    but here is your answers

    in c# events are in the property box, click the lightening bolt to list all the events for an object

    and in c#, me = this

    this.Caption = "blah";

  3. #3

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Thanks, I'll pick up a book eventually. I need to get the woman's car fixed I hit as well as my own before I start going out and spending money.



    I should be able to get most of it from now on though. I can't believe I didn't think of this, I know C++ and C++ uses that. bah

  4. #4
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    Unlike in VB.NET where an event is like just an event, in C# an event is just a function pointer so to manually declare an event just do:

    this.<event> += new <delegate>(function_to_point);
    \m/\m/

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by PT Exorcist
    Unlike in VB.NET where an event is like just an event, in C# an event is just a function pointer so to manually declare an event just do:

    this.<event> += new <delegate>(function_to_point);
    Events in .NET work the same way in VB.NET and C# . Both are safepointers that encapsulate event handlers which in turn call them back . So they are exactly alike .

  6. #6
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    What I've said is that VB.NET hides all of that.
    I programmed in vb.net for some months and only when i came to C# I realised what events really were -- function pointers
    \m/\m/

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by PT Exorcist
    What I've said is that VB.NET hides all of that.
    I programmed in vb.net for some months and only when i came to C# I realised what events really were -- function pointers
    To some extent , this is true but when working with custome events , then you are working with delegates (pointers) and you can see that .

  8. #8
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Originally posted by Pirate
    To some extent , this is true but when working with custome events , then you are working with delegates (pointers) and you can see that .
    You are ALWAYS using delegates (which are function pointers). VB.Net will hide it for you by using the 'Handles' statement when you are dealing with controls and what not, but don't mistake this hidden functionality as different. Under the hood VB.Net is using delegates for you.

    Delegates allow one event to call one or several methods (functions/subs if you are a vb person). This means it is basically a pointer holder. It will hold pointers to methods that subscribe to the event. When a control/object raises a event, the delegate will call each of the subscribed functions.

    This is why you can subscribe/unsubscribe from a event during run time.

  9. #9
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    You can also use Delegates in VB.NET if you want to do things the hard way.

  10. #10
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by hellswraith
    You are ALWAYS using delegates (which are function pointers). VB.Net will hide it for you by using the 'Handles' statement when you are dealing with controls and what not, but don't mistake this hidden functionality as different. Under the hood VB.Net is using delegates for you.

    Delegates allow one event to call one or several methods (functions/subs if you are a vb person). This means it is basically a pointer holder. It will hold pointers to methods that subscribe to the event. When a control/object raises a event, the delegate will call each of the subscribed functions.

    This is why you can subscribe/unsubscribe from a event during run time.
    This is what I'm saying . The difference between VB.NET and C# is the syntax (VB.NET uses Addressof + handler) but C# use +/- operators to subscribe/unsubscribe .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width