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. how to fire or raise an event

how to fire or raise an event

Scheduled Pinned Locked Moved C#
csharptutorial
2 Posts 2 Posters 1 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.
  • M Offline
    M Offline
    Mardawi
    wrote on last edited by
    #1

    Hi i'm doing a user control in C#, where i have textbox controles, when ever a textbox is clicked (when the event textBox1.Click is fired) i need to FIRE the this.Load event (not to call the this.Load event handler method!!!). Because when i use this conrole in a form the event handler method will change. Thanks a lot PS: if you know how to do it on other .net languages tell me...it will be very helpful

    L 1 Reply Last reply
    0
    • M Mardawi

      Hi i'm doing a user control in C#, where i have textbox controles, when ever a textbox is clicked (when the event textBox1.Click is fired) i need to FIRE the this.Load event (not to call the this.Load event handler method!!!). Because when i use this conrole in a form the event handler method will change. Thanks a lot PS: if you know how to do it on other .net languages tell me...it will be very helpful

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      1. Define an event:

      public event EventHandler TextBoxClick;

      2. Define a method to fire the event:

      protected vitual void OnTextBoxClick(object sender, EventArgs e)
      {
      if (TextBoxClick != null) TextBoxClick(sender, e);
      }

      3. Fire the event from the associated event eg:

      textBox1.Click += new EventHandler(Textboxclicked);
      textBox2.Click += new EventHandler(Textboxclicked);
      textBox3.Click += new EventHandler(Textboxclicked);
      textBox4.Click += new EventHandler(Textboxclicked);

      ...

      void Textboxclicked(object sender, EventHandler e)
      {
      OnTextBoxClick(sender, e);
      }

      4. Implemeted the TextBoxClick event on the form.

      mControl.TextBoxClick += new EventHandler(methodtohandleevent);

      There you have it! Merry Xmas :) WebBoxes - Yet another collapsable control, but it relies on a "graphics server" for dynamic pretty rounded corners, cool arrows and unlimited font support.

      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