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. C#
  4. Suspending event handling

Suspending event handling

Scheduled Pinned Locked Moved C#
question
2 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.
  • D Offline
    D Offline
    Drew McGhie
    wrote on last edited by
    #1

    On a usercontrol, is there an easy way to suspend all event handling on the control and all child controls? I don't want my event handling to keep firing as I set the form up, rather I just want to call a set of calculating/formatting functions just once in Load(), and then have all the events (which call the calculating/formatting functions) start firing. Right now I have an if statement in each event that ties to a boolean that I set when I want events to start working, but it seems like there might be an easier way. Any suggestions?

    A 1 Reply Last reply
    0
    • D Drew McGhie

      On a usercontrol, is there an easy way to suspend all event handling on the control and all child controls? I don't want my event handling to keep firing as I set the form up, rather I just want to call a set of calculating/formatting functions just once in Load(), and then have all the events (which call the calculating/formatting functions) start firing. Right now I have an if statement in each event that ties to a boolean that I set when I want events to start working, but it seems like there might be an easier way. Any suggestions?

      A Offline
      A Offline
      Abisodun
      wrote on last edited by
      #2

      How about using one method to remove the handlers and another to add. Then you're swichting them on and off in just two places. i.e. private void RemoveHandlers() { button1.Click -= new EventHandler(clickHandler); ---- } private void AddHandlers() { button1.Click += new EventHandler(clickHandler); ---- }

      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