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 activate event procedure

How to activate event procedure

Scheduled Pinned Locked Moved C#
csharptutorialquestion
9 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
    D Shen
    wrote on last edited by
    #1

    Hi, I am looking for a way to activate an event procedure, such as combox_clicked, without really clicking on the control . I remember in VB we can do thing like that (combox_clicked = true). Just wonder can we do this in C#? I appreciate your inputs.

    L 1 Reply Last reply
    0
    • D D Shen

      Hi, I am looking for a way to activate an event procedure, such as combox_clicked, without really clicking on the control . I remember in VB we can do thing like that (combox_clicked = true). Just wonder can we do this in C#? I appreciate your inputs.

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

      Hi You just need to call the event handler :) Like: First derive from Button, then add the following: public void CallButtonClick() { base.OnClick(this, EventArgs.Empty); } Now , call the function from your code :) Hope this helps, there seems to be many ways to do this though. Give them a chance! Do it for the kittens, dear God, the kittens!

      D 1 Reply Last reply
      0
      • L leppie

        Hi You just need to call the event handler :) Like: First derive from Button, then add the following: public void CallButtonClick() { base.OnClick(this, EventArgs.Empty); } Now , call the function from your code :) Hope this helps, there seems to be many ways to do this though. Give them a chance! Do it for the kittens, dear God, the kittens!

        D Offline
        D Offline
        D Shen
        wrote on last edited by
        #3

        Hi Leppie, I am not sure if I understand what you mean by :confused: leppie wrote: First derive from Button, then add the following: public void CallButtonclick() { base.onclick(this, EventArgs.Empty); } Can you please give more detailed explaination? I really appreciate that!!;)

        L 2 Replies Last reply
        0
        • D D Shen

          Hi Leppie, I am not sure if I understand what you mean by :confused: leppie wrote: First derive from Button, then add the following: public void CallButtonclick() { base.onclick(this, EventArgs.Empty); } Can you please give more detailed explaination? I really appreciate that!!;)

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

          D Shen wrote: I am not sure if I understand what you mean by It's the beauty of inheritance :) OK. Lets see how/why I say that :) 1. What we want is a button that we can programatically fire events. It makes sense to add this functionality to the Button class. So we make one:

          public class ButtonEx():System.Windows.Forms.Button
          {
          public void CallButtonclick()
          {
          base.OnClick(EventArgs.Empty); // sorry mistake in first post :)
          }
          }

          2. We replace our existing Button in the in the form with our new ButtonEx.

          private System.Windows.Forms.Button button1; //now becomes
          private ButtonEx button1;

          And in the windows forms designer region, change :

          button1 = new System.Windows.Forms.Button(); //now changes to
          button1 = new ButtonEx();

          Be sure to save before viewing in the designer(in fact close it beforehand, it does more harm than good :laugh:). 3. Finally we just call our new ButtonEx's CallButtonClick methods as follows:

          button1.CallButtonClick();

          NOTE: If you'll be calling this method from thread u will need to invoke it. I'm not 100% sure, but it would look something like this:

          button1.Invoke( new MethodInvoker(button1.CallButtonClick));

          Hope this adds some insight :) Give them a chance! Do it for the kittens, dear God, the kittens!

          D 2 Replies Last reply
          0
          • D D Shen

            Hi Leppie, I am not sure if I understand what you mean by :confused: leppie wrote: First derive from Button, then add the following: public void CallButtonclick() { base.onclick(this, EventArgs.Empty); } Can you please give more detailed explaination? I really appreciate that!!;)

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

            Sorry, I'm a bit DOPEY :-O I didnt see that it was a combobox you were talking about, but the way to do it is the same, just follow the steps :) Give them a chance! Do it for the kittens, dear God, the kittens!

            1 Reply Last reply
            0
            • L leppie

              D Shen wrote: I am not sure if I understand what you mean by It's the beauty of inheritance :) OK. Lets see how/why I say that :) 1. What we want is a button that we can programatically fire events. It makes sense to add this functionality to the Button class. So we make one:

              public class ButtonEx():System.Windows.Forms.Button
              {
              public void CallButtonclick()
              {
              base.OnClick(EventArgs.Empty); // sorry mistake in first post :)
              }
              }

              2. We replace our existing Button in the in the form with our new ButtonEx.

              private System.Windows.Forms.Button button1; //now becomes
              private ButtonEx button1;

              And in the windows forms designer region, change :

              button1 = new System.Windows.Forms.Button(); //now changes to
              button1 = new ButtonEx();

              Be sure to save before viewing in the designer(in fact close it beforehand, it does more harm than good :laugh:). 3. Finally we just call our new ButtonEx's CallButtonClick methods as follows:

              button1.CallButtonClick();

              NOTE: If you'll be calling this method from thread u will need to invoke it. I'm not 100% sure, but it would look something like this:

              button1.Invoke( new MethodInvoker(button1.CallButtonClick));

              Hope this adds some insight :) Give them a chance! Do it for the kittens, dear God, the kittens!

              D Offline
              D Offline
              D Shen
              wrote on last edited by
              #6

              Thank you, leppie. It really helps!:laugh:

              1 Reply Last reply
              0
              • L leppie

                D Shen wrote: I am not sure if I understand what you mean by It's the beauty of inheritance :) OK. Lets see how/why I say that :) 1. What we want is a button that we can programatically fire events. It makes sense to add this functionality to the Button class. So we make one:

                public class ButtonEx():System.Windows.Forms.Button
                {
                public void CallButtonclick()
                {
                base.OnClick(EventArgs.Empty); // sorry mistake in first post :)
                }
                }

                2. We replace our existing Button in the in the form with our new ButtonEx.

                private System.Windows.Forms.Button button1; //now becomes
                private ButtonEx button1;

                And in the windows forms designer region, change :

                button1 = new System.Windows.Forms.Button(); //now changes to
                button1 = new ButtonEx();

                Be sure to save before viewing in the designer(in fact close it beforehand, it does more harm than good :laugh:). 3. Finally we just call our new ButtonEx's CallButtonClick methods as follows:

                button1.CallButtonClick();

                NOTE: If you'll be calling this method from thread u will need to invoke it. I'm not 100% sure, but it would look something like this:

                button1.Invoke( new MethodInvoker(button1.CallButtonClick));

                Hope this adds some insight :) Give them a chance! Do it for the kittens, dear God, the kittens!

                D Offline
                D Offline
                D Shen
                wrote on last edited by
                #7

                leppie, Here comes a minor problem :-O When I compile the code, I got "...does not contain a definition for..." this button1. I followed the order you post here, but....:~ Please help!!

                D 1 Reply Last reply
                0
                • D D Shen

                  leppie, Here comes a minor problem :-O When I compile the code, I got "...does not contain a definition for..." this button1. I followed the order you post here, but....:~ Please help!!

                  D Offline
                  D Offline
                  D Shen
                  wrote on last edited by
                  #8

                  leppie, I found the problem, it was so stupid.....(typo:-O)

                  L 1 Reply Last reply
                  0
                  • D D Shen

                    leppie, I found the problem, it was so stupid.....(typo:-O)

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

                    Hehe, thought it was either that or the designer screw'd up the UI :laugh: Give them a chance! Do it for the kittens, dear God, the kittens! As seen on MS File Transfer: Please enter an integer between 1 and 2.

                    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