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. ...(object sender, System.EventArgs e)

...(object sender, System.EventArgs e)

Scheduled Pinned Locked Moved C#
questionhelptutorial
6 Posts 3 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.
  • I Offline
    I Offline
    Imran Adam
    wrote on last edited by
    #1

    This is a really easy question i hope....... for example you have the following code; private void Form1_Load**(object sender, System.EventArgs e)** i would like to know what the bold part means?? im not too concerened about Form1_Load event, its just the parameters of any event. I cant seem to understand:mad: I have tried looking in books but had no success. Please help

    Cheers :)

    N S 2 Replies Last reply
    0
    • I Imran Adam

      This is a really easy question i hope....... for example you have the following code; private void Form1_Load**(object sender, System.EventArgs e)** i would like to know what the bold part means?? im not too concerened about Form1_Load event, its just the parameters of any event. I cant seem to understand:mad: I have tried looking in books but had no success. Please help

      Cheers :)

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      hustler2005 wrote:

      I have tried looking in books but had no success.

      Don't understand why. There is plenty of documentation, and you couldn't find anything? sender is rather obvious, the sender of the event. EventArgs is the data generated from the event


      only two letters away from being an asset

      I 1 Reply Last reply
      0
      • N Not Active

        hustler2005 wrote:

        I have tried looking in books but had no success.

        Don't understand why. There is plenty of documentation, and you couldn't find anything? sender is rather obvious, the sender of the event. EventArgs is the data generated from the event


        only two letters away from being an asset

        I Offline
        I Offline
        Imran Adam
        wrote on last edited by
        #3

        sorry, what i meant is "i have had no success" in understanding what i have read. if someone could explain it a lil more clear/easier to understand?? it would make my day! :-D

        Cheers :)

        1 Reply Last reply
        0
        • I Imran Adam

          This is a really easy question i hope....... for example you have the following code; private void Form1_Load**(object sender, System.EventArgs e)** i would like to know what the bold part means?? im not too concerened about Form1_Load event, its just the parameters of any event. I cant seem to understand:mad: I have tried looking in books but had no success. Please help

          Cheers :)

          S Offline
          S Offline
          Scott Dorman
          wrote on last edited by
          #4

          As Mark said, there is already a lot of information about this online. Anyway, the sender parameter is an object representation of the control that caused the event to be sent. It is an object, which means that you need to have some knowledge of what the actual sender is supposed to be if you want to use it inside the event handler. In order to use the sender you need to cast it to the appropriate type. In the case of your example, you would need to do one of the following:

          private void Form1_Load(object sender, System.EventArgs e)
          {
          Form f = sender as Form;
          if (f != null)
          {
          // do something here
          }
          }

          or

          private void Form1_Load(object sender, System.EventArgs e)
          {
          Form f = (Form)sender;
          // do something here
          }

          To me, the preferred way is the first one since it is a bit safer. The e parameter represents the "EventArgs" of the event. In reality, EventArgs is a class that is used to hold the data generated by the event that could be used within the event handler. All events should use either the System.EventArgs class or a custom (derived) System.EventArgs class. The default System.EventArgs class maintains no data about the event.

          Scott.


          —In just two days, tomorrow will be yesterday. [Forum Guidelines] [Articles] [Blog]

          I 1 Reply Last reply
          0
          • S Scott Dorman

            As Mark said, there is already a lot of information about this online. Anyway, the sender parameter is an object representation of the control that caused the event to be sent. It is an object, which means that you need to have some knowledge of what the actual sender is supposed to be if you want to use it inside the event handler. In order to use the sender you need to cast it to the appropriate type. In the case of your example, you would need to do one of the following:

            private void Form1_Load(object sender, System.EventArgs e)
            {
            Form f = sender as Form;
            if (f != null)
            {
            // do something here
            }
            }

            or

            private void Form1_Load(object sender, System.EventArgs e)
            {
            Form f = (Form)sender;
            // do something here
            }

            To me, the preferred way is the first one since it is a bit safer. The e parameter represents the "EventArgs" of the event. In reality, EventArgs is a class that is used to hold the data generated by the event that could be used within the event handler. All events should use either the System.EventArgs class or a custom (derived) System.EventArgs class. The default System.EventArgs class maintains no data about the event.

            Scott.


            —In just two days, tomorrow will be yesterday. [Forum Guidelines] [Articles] [Blog]

            I Offline
            I Offline
            Imran Adam
            wrote on last edited by
            #5

            Thanks Scott/Matt for your input. You mention there is alot of documentation online, can you suggest a good starting point?? This would be very help indeed.

            Cheers :)

            S 1 Reply Last reply
            0
            • I Imran Adam

              Thanks Scott/Matt for your input. You mention there is alot of documentation online, can you suggest a good starting point?? This would be very help indeed.

              Cheers :)

              S Offline
              S Offline
              Scott Dorman
              wrote on last edited by
              #6

              Sure, a good starting point would probably be MSDN. Here are some links: EventArgs Class (System)[^] EventHandler Delegate (System)[^] Events and Delegates[^] Consuming Events[^]

              Scott.


              —In just two days, tomorrow will be yesterday. [Forum Guidelines] [Articles] [Blog]

              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