Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Custom event on variable change

Custom event on variable change

Scheduled Pinned Locked Moved Visual Basic
questioncsharp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 2 Offline
    2 Offline
    2hdass
    wrote on last edited by
    #1

    i am not too familiar with events in .net I am wishing make my program fire an event when a variable changes, how can I do that? thx

    C 1 Reply Last reply
    0
    • 2 2hdass

      i am not too familiar with events in .net I am wishing make my program fire an event when a variable changes, how can I do that? thx

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      2hdass wrote:

      I am wishing make my program fire an event when a variable changes, how can I do that?

      You can't. If the variable is a field on the class then you should encapsulate it in a property and have the property's setter fire the event. This article[^] shows how to use events (See the sibling to sibling section). The event is fired from a method, but a property is just syntactic sugar for a get or set method anyway.


      Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website

      2 1 Reply Last reply
      0
      • C Colin Angus Mackay

        2hdass wrote:

        I am wishing make my program fire an event when a variable changes, how can I do that?

        You can't. If the variable is a field on the class then you should encapsulate it in a property and have the property's setter fire the event. This article[^] shows how to use events (See the sibling to sibling section). The event is fired from a method, but a property is just syntactic sugar for a get or set method anyway.


        Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website

        2 Offline
        2 Offline
        2hdass
        wrote on last edited by
        #3

        Thx The app I am writing actually wants to read the System's Power State using P/Invoke to the Win32 API on my WM5.0 PDA. I am wondering if there is a predefined event already included in the library/

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups