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. Event Handler

Event Handler

Scheduled Pinned Locked Moved C#
questionhelptutorial
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.
  • A Offline
    A Offline
    AlexB47
    wrote on last edited by
    #1

    A question ... I have 2 classes .. in a class1 (form) I call a function, situated in class2, for draw an image. In the middle of this function, i want send an event to class1 (for invalidate a rect etc) ... can you help me, with an example, to implement an event handler? thanks a lot.

    Alex

    D 1 Reply Last reply
    0
    • A AlexB47

      A question ... I have 2 classes .. in a class1 (form) I call a function, situated in class2, for draw an image. In the middle of this function, i want send an event to class1 (for invalidate a rect etc) ... can you help me, with an example, to implement an event handler? thanks a lot.

      Alex

      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      public class Class1
      {
      private Class2 class2;
      public Class1()
      {
      class2 = new Class2();
      class2.Class2Event += new EventHandler(class2_Class2Event);
      class2.Class2Function();
      }

      void class2\_Class2Event(object sender, EventArgs e)
      {
          // Respond to event here
      }
      

      }
      public class Class2
      {
      public event EventHandler Class2Event;

      public void Class2Function()
      {
          OnClass2Event(EventArgs.Empty);
      }
      
      protected virtual void OnClass2Event(EventArgs e)
      {
          EventHandler eh = Class2Event;
          if (eh != null)
              eh(this, e);
      }
      

      }

      Dave
      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
      Why are you using VB6? Do you hate yourself? (Christian Graus)

      A 1 Reply Last reply
      0
      • D DaveyM69

        public class Class1
        {
        private Class2 class2;
        public Class1()
        {
        class2 = new Class2();
        class2.Class2Event += new EventHandler(class2_Class2Event);
        class2.Class2Function();
        }

        void class2\_Class2Event(object sender, EventArgs e)
        {
            // Respond to event here
        }
        

        }
        public class Class2
        {
        public event EventHandler Class2Event;

        public void Class2Function()
        {
            OnClass2Event(EventArgs.Empty);
        }
        
        protected virtual void OnClass2Event(EventArgs e)
        {
            EventHandler eh = Class2Event;
            if (eh != null)
                eh(this, e);
        }
        

        }

        Dave
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
        Why are you using VB6? Do you hate yourself? (Christian Graus)

        A Offline
        A Offline
        AlexB47
        wrote on last edited by
        #3

        thanks a lot! :)

        Alex

        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