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. Open a form?

Open a form?

Scheduled Pinned Locked Moved C#
helpquestion
6 Posts 3 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.
  • W Offline
    W Offline
    Wolf92
    wrote on last edited by
    #1

    Hi, why doesn't my code work? I have two forms in my windows application, I want the user to click on a button called btnCustomize and the other form (called frmCustomize) to open. The first form is called reminder. Here is the code that I have tried : private void btnCustomize_Click(object sender, EventArgs e) { frmCustomize.Show(); } I have also tried variations on this like .ShowDialog(); and such. Can you help?

    S 1 Reply Last reply
    0
    • W Wolf92

      Hi, why doesn't my code work? I have two forms in my windows application, I want the user to click on a button called btnCustomize and the other form (called frmCustomize) to open. The first form is called reminder. Here is the code that I have tried : private void btnCustomize_Click(object sender, EventArgs e) { frmCustomize.Show(); } I have also tried variations on this like .ShowDialog(); and such. Can you help?

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      Wolf92 wrote:

      why doesn't my code work?

      What exactly does that mean? Are you getting any exceptions? Did you eventually forget to create an instance of the form and assign it to the frmCustomize field.


      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

      www.troschuetz.de

      W 1 Reply Last reply
      0
      • S Stefan Troschuetz

        Wolf92 wrote:

        why doesn't my code work?

        What exactly does that mean? Are you getting any exceptions? Did you eventually forget to create an instance of the form and assign it to the frmCustomize field.


        "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

        www.troschuetz.de

        W Offline
        W Offline
        Wolf92
        wrote on last edited by
        #3

        I think I am typing in the wrong code? I want that when the user clicks 'btnCustomize' the form 'frmCustomize' displays. What is the code for this? This is the error message I get when I type in : private void btnCustomize_Click(object sender, EventArgs e) { frmCustomize.Show(); } It says : Error 1 An object reference is required for the nonstatic field, method, or property 'System.Windows.Forms.Control.Show()' D:\Documents and Settings\Sophie\My Documents\Programming\Programs\C#\Reminder\Reminder\reminder.cs 66 13 Reminder

        S 1 Reply Last reply
        0
        • W Wolf92

          I think I am typing in the wrong code? I want that when the user clicks 'btnCustomize' the form 'frmCustomize' displays. What is the code for this? This is the error message I get when I type in : private void btnCustomize_Click(object sender, EventArgs e) { frmCustomize.Show(); } It says : Error 1 An object reference is required for the nonstatic field, method, or property 'System.Windows.Forms.Control.Show()' D:\Documents and Settings\Sophie\My Documents\Programming\Programs\C#\Reminder\Reminder\reminder.cs 66 13 Reminder

          S Offline
          S Offline
          Stefan Troschuetz
          wrote on last edited by
          #4

          You have to create an instance of your custom form on which you can call Show afterwards.

          MyForm myFormInstance = new MyForm();
          myFormInstance.Show();

          I suggest you do some reading on OOP.


          "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

          www.troschuetz.de

          S 1 Reply Last reply
          0
          • S Stefan Troschuetz

            You have to create an instance of your custom form on which you can call Show afterwards.

            MyForm myFormInstance = new MyForm();
            myFormInstance.Show();

            I suggest you do some reading on OOP.


            "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

            www.troschuetz.de

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

            Stefan Troschütz wrote:

            I suggest you do some reading on OOP

            that right cuase when u work with C# u should look to everything form OOP view the form u created is a class inherteted form WindosForm class and all other objects r the same

            W 1 Reply Last reply
            0
            • S shabonaa

              Stefan Troschütz wrote:

              I suggest you do some reading on OOP

              that right cuase when u work with C# u should look to everything form OOP view the form u created is a class inherteted form WindosForm class and all other objects r the same

              W Offline
              W Offline
              Wolf92
              wrote on last edited by
              #6

              Thank you! I have it working properly now. I tried something like that, but it didn't work. Thank 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