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 form from another form

Open form from another form

Scheduled Pinned Locked Moved C#
databasecsharpsql-serversysadminhelp
5 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.
  • P Offline
    P Offline
    piticcotoc
    wrote on last edited by
    #1

    Hy, I'm designing an application that accesses SQL Server from C#. I have a form that runs first where i select the sql server and database. When i click a button it's should assign the hostname and database for the connection string, close and open another form (the main application). The problem is when the select form closes, the main form appears for 1 sec and then the whole application closes. I've ran the app step by step, everything is ok, the variables are assigned but it automaticly calls the dispose method for the second form. This is the code from the first form that runs at app start (selectserver form)

    private void btnSelectServer_Click(object sender, EventArgs e)
    {
    <<assign values from control boxes>>
    frmMain main = new frmMain();
    main.Show();
    this.Close();
    }

    M D 2 Replies Last reply
    0
    • P piticcotoc

      Hy, I'm designing an application that accesses SQL Server from C#. I have a form that runs first where i select the sql server and database. When i click a button it's should assign the hostname and database for the connection string, close and open another form (the main application). The problem is when the select form closes, the main form appears for 1 sec and then the whole application closes. I've ran the app step by step, everything is ok, the variables are assigned but it automaticly calls the dispose method for the second form. This is the code from the first form that runs at app start (selectserver form)

      private void btnSelectServer_Click(object sender, EventArgs e)
      {
      <<assign values from control boxes>>
      frmMain main = new frmMain();
      main.Show();
      this.Close();
      }

      M Offline
      M Offline
      Mbah Dhaim
      wrote on last edited by
      #2

      1. In main entry point use your MainForm in Application.Run(new YourMainForm) 2. In your main form load event call your Sql Server Form Setting with showdialog and verify the settings 3. Close your Sql Server Form Setting. hope it helps

      dhaim ing ngarso sung tulodho, ing madyo mangun karso, tut wuri handayani. "Ki Hajar Dewantoro" in the front line gave a lead, in the middle line build goodwill, in the behind give power support

      P 1 Reply Last reply
      0
      • M Mbah Dhaim

        1. In main entry point use your MainForm in Application.Run(new YourMainForm) 2. In your main form load event call your Sql Server Form Setting with showdialog and verify the settings 3. Close your Sql Server Form Setting. hope it helps

        dhaim ing ngarso sung tulodho, ing madyo mangun karso, tut wuri handayani. "Ki Hajar Dewantoro" in the front line gave a lead, in the middle line build goodwill, in the behind give power support

        P Offline
        P Offline
        piticcotoc
        wrote on last edited by
        #3

        But this way the main form would be loaded first. And I want to load the server form only, and if selected the appropriate server+database, close it and open the main form.

        M 1 Reply Last reply
        0
        • P piticcotoc

          But this way the main form would be loaded first. And I want to load the server form only, and if selected the appropriate server+database, close it and open the main form.

          M Offline
          M Offline
          Mbah Dhaim
          wrote on last edited by
          #4

          in main entry of your application use this

          using (SqlServerForm sqlServerForm = new SqlServerForm())
          {
          if (sqlServerForm.ShowDialog() == DialogResult.OK)
          {
          Application.Run(new frmMain());
          }
          }

          piticcotoc wrote:

          and if selected the appropriate server+database

          set the dialog result of sqlserverform to OK to close the form hope it helps

          dhaim ing ngarso sung tulodho, ing madyo mangun karso, tut wuri handayani. "Ki Hajar Dewantoro" in the front line gave a lead, in the middle line build goodwill, in the behind give power support

          1 Reply Last reply
          0
          • P piticcotoc

            Hy, I'm designing an application that accesses SQL Server from C#. I have a form that runs first where i select the sql server and database. When i click a button it's should assign the hostname and database for the connection string, close and open another form (the main application). The problem is when the select form closes, the main form appears for 1 sec and then the whole application closes. I've ran the app step by step, everything is ok, the variables are assigned but it automaticly calls the dispose method for the second form. This is the code from the first form that runs at app start (selectserver form)

            private void btnSelectServer_Click(object sender, EventArgs e)
            {
            <<assign values from control boxes>>
            frmMain main = new frmMain();
            main.Show();
            this.Close();
            }

            D Offline
            D Offline
            daiduongbk
            wrote on last edited by
            #5

            Change: private void btnSelectServer_Click(object sender, EventArgs e) { <<assign values from control boxes>> frmMain main = new frmMain(); main.Show(); this.Hide(); } ------- Nguyen Dai Duong Ha Noi University of Technology daiduongbk@gmail.com

            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