Open form from another form
-
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();
} -
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();
}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 helpsdhaim 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. 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 helpsdhaim 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
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.
-
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.
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
-
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();
}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