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. Buttons and form show and close

Buttons and form show and close

Scheduled Pinned Locked Moved C#
help
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.
  • S Offline
    S Offline
    Star09
    wrote on last edited by
    #1
    yesb.Click += new System.EventHandler(this.Show());
    nob.Click += new System.EventHandler(this.Close());
    

    this is the error I keep getting: An object reference is required for the nonstatic field, method, or property 'System.Windows.Forms.Control.Show()' Same thing for this.Close() as well. I have two buttons, one should reload the application, and the other closes it.

    L D 2 Replies Last reply
    0
    • S Star09
      yesb.Click += new System.EventHandler(this.Show());
      nob.Click += new System.EventHandler(this.Close());
      

      this is the error I keep getting: An object reference is required for the nonstatic field, method, or property 'System.Windows.Forms.Control.Show()' Same thing for this.Close() as well. I have two buttons, one should reload the application, and the other closes it.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Interesting Have you tried pressing TAB twice after writing the +=? Putting the show/close in those methods may be more.. reliable (as in: no chance that it could go wrong)

      S 1 Reply Last reply
      0
      • L Lost User

        Interesting Have you tried pressing TAB twice after writing the +=? Putting the show/close in those methods may be more.. reliable (as in: no chance that it could go wrong)

        S Offline
        S Offline
        Star09
        wrote on last edited by
        #3

        No I haven't. I used this.Close() before and it worked fine.

        L 1 Reply Last reply
        0
        • S Star09
          yesb.Click += new System.EventHandler(this.Show());
          nob.Click += new System.EventHandler(this.Close());
          

          this is the error I keep getting: An object reference is required for the nonstatic field, method, or property 'System.Windows.Forms.Control.Show()' Same thing for this.Close() as well. I have two buttons, one should reload the application, and the other closes it.

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

          You can't call Show or Close this way unless you overload the methods i.e

          //Note: the parameters are defined by the delegate so no parenthesis
          yesb.Click += new EventHandler(Show);

          void Show(object sender, EventArgs e)
          {
          Show();
          }

          The normal way is to have a Click event handler and call Show from there - the same really - just a more logical name.

          yesb.Click += new EventHandler(yesb_Click);

          void yesb_Click(object sender, EventArgs e)
          {
          Show();
          }

          Dave
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
          Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
          Why are you using VB6? Do you hate yourself? (Christian Graus)

          S 1 Reply Last reply
          0
          • D DaveyM69

            You can't call Show or Close this way unless you overload the methods i.e

            //Note: the parameters are defined by the delegate so no parenthesis
            yesb.Click += new EventHandler(Show);

            void Show(object sender, EventArgs e)
            {
            Show();
            }

            The normal way is to have a Click event handler and call Show from there - the same really - just a more logical name.

            yesb.Click += new EventHandler(yesb_Click);

            void yesb_Click(object sender, EventArgs e)
            {
            Show();
            }

            Dave
            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
            Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
            Why are you using VB6? Do you hate yourself? (Christian Graus)

            S Offline
            S Offline
            Star09
            wrote on last edited by
            #5

            Thank you! It worked :)

            1 Reply Last reply
            0
            • S Star09

              No I haven't. I used this.Close() before and it worked fine.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Of course it does, but I don't think you're putting it in the right place. If you had pressed tab twice, you would get code like DaveyM69 shows you.

              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