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 have program respond to code created button

How to have program respond to code created button

Scheduled Pinned Locked Moved C#
tutorialquestion
9 Posts 4 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.
  • J Offline
    J Offline
    Jordanwb
    wrote on last edited by
    #1

    In the code I have it create a form, then a button. The button is added to the newly created form. When the user clicks on the button I want it to run a function that includes closing the form. Can this be done?

    M L 2 Replies Last reply
    0
    • J Jordanwb

      In the code I have it create a form, then a button. The button is added to the newly created form. When the user clicks on the button I want it to run a function that includes closing the form. Can this be done?

      M Offline
      M Offline
      MickCurley
      wrote on last edited by
      #2

      Jordanwb wrote:

      Can this be done?

      Of course it can be done...just a shot in the dark here...:sigh: maybe form.close();

      A craft is an enemy if not well learned.

      J 1 Reply Last reply
      0
      • M MickCurley

        Jordanwb wrote:

        Can this be done?

        Of course it can be done...just a shot in the dark here...:sigh: maybe form.close();

        A craft is an enemy if not well learned.

        J Offline
        J Offline
        Jordanwb
        wrote on last edited by
        #3

        I know how to do that, but what I want to know is how to have the program catch the button being pressed.

        M 1 Reply Last reply
        0
        • J Jordanwb

          I know how to do that, but what I want to know is how to have the program catch the button being pressed.

          M Offline
          M Offline
          MickCurley
          wrote on last edited by
          #4

          Place the code to close the form between the curly braces.....

          private void button1_Click(object sender, EventArgs e)
          {
          formwhatever.close();
          }

          This is fairly basic you know. Maybe you need a beginners book ???

          A craft is an enemy if not well learned.

          J 1 Reply Last reply
          0
          • M MickCurley

            Place the code to close the form between the curly braces.....

            private void button1_Click(object sender, EventArgs e)
            {
            formwhatever.close();
            }

            This is fairly basic you know. Maybe you need a beginners book ???

            A craft is an enemy if not well learned.

            J Offline
            J Offline
            Jordanwb
            wrote on last edited by
            #5

            Actually I found what I was looking for: this.add_button.Click += new System.EventHandler(this.save_content);

            G 1 Reply Last reply
            0
            • J Jordanwb

              In the code I have it create a form, then a button. The button is added to the newly created form. When the user clicks on the button I want it to run a function that includes closing the form. Can this be done?

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              You also need to wire your handler to the event, as in: button.Click+=new EventHandler(button1_Clicked); Make sure this line executes only once (you can do it where you create the Button). In fact you can and often should program exactly the way Visual Designer does it for you when you add a Control graphically; just have a look in the code generated by Visual itself! :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets


              J 1 Reply Last reply
              0
              • J Jordanwb

                Actually I found what I was looking for: this.add_button.Click += new System.EventHandler(this.save_content);

                G Offline
                G Offline
                gericooper
                wrote on last edited by
                #7

                at least 3-4 articles popped up in "C# event handling" on Codeproject It is worth the time reading through. 1-2 hour & you'll be fine....

                1 Reply Last reply
                0
                • L Luc Pattyn

                  You also need to wire your handler to the event, as in: button.Click+=new EventHandler(button1_Clicked); Make sure this line executes only once (you can do it where you create the Button). In fact you can and often should program exactly the way Visual Designer does it for you when you add a Control graphically; just have a look in the code generated by Visual itself! :)

                  Luc Pattyn [Forum Guidelines] [My Articles]


                  this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets


                  J Offline
                  J Offline
                  Jordanwb
                  wrote on last edited by
                  #8

                  That's actually how I found the needed code (looked at Visual's generated code)

                  L 1 Reply Last reply
                  0
                  • J Jordanwb

                    That's actually how I found the needed code (looked at Visual's generated code)

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #9

                    There are alternatives, such as - reading the documentation (MSDN, Google), - reading some articles, maybe from CodeProject - working your way through a book on either a programming language or Visual Studio. :)

                    Luc Pattyn [Forum Guidelines] [My Articles]


                    this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets


                    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