Click here to Skip to main content
15,888,088 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have form1 and form2.

when ever the logins (form1) succeed then i will navigate to form2,before navigate to form2 am trying to close form1,that's not happening.am not sure what am missing here.
C#
 Login logform = new Login();
 logform.Dispose();
//i tried logform.close(), and this.close() (throwing error)
//Login successful then navigate to Form2.
DbNavigate.frmDataGridPaging form = new DbNavigate.frmDataGridPaging();
                    form.ShowDialog(this);

thanks in Advance
Posted
Updated 10-Aug-11 21:35pm
v2

It appears that your login form is the application main form. The application main form should typically be kept alive until the application ends.

If you want to display a form before the main form, then you should display a modal form and when done display the main form.

Anyway for that purpose, you would have to override some code as your application does not follows the standard pattern.

A simpler option might be to display the "true" application first and when shown display the login form.

I would think that the problem is that the application still want to uses the login form as you have called Application.Run(new Login());

Your code is simple... but you are trying to do something unusual by not having your "main form" alive until your application ends.

Changing the main form dynamically need some tricks to make it works properly including proper display of button in the task bar... without move or annoying temporary changes (2 buttons or no button for while displaying the next form).

Thus in pratice, if you don't follow the standard pattern, it will be up to you to make it work by overriding the appropriate methods in the application, the application context and your form including managing the closing of the application when the last form is closed.
 
Share this answer
 
You don't want to create object of login from while closing. Just you write this.close() in the first line and call then cal form2.
Try this.
this.close()
//Login successful then navigate to Form2.
DbNavigate.frmDataGridPaging form = new DbNavigate.frmDataGridPaging();
                    form.ShowDialog(this);
 
Share this answer
 
Comments
shan1395 11-Aug-11 3:41am    
even i tried like this

this.Close();
//Login successful then navigate to Form2.
DbNavigate.frmDataGridPaging form = new DbNavigate.frmDataGridPaging();
form.ShowDialog(this);


it throws exception below
Cannot access a disposed object.
Object name: 'Login'.
Toniyo Jackson 11-Aug-11 3:51am    
Are you disposing Login form object in any place?
Dalek Dave 11-Aug-11 3:41am    
Bugger, you beat me to it by seconds!
There was no answer when I opened my response, and then you appeared! :)
Toniyo Jackson 11-Aug-11 3:52am    
Its all in the game DD :)
Try this.Close();
 
Share this answer
 
Comments
shan1395 11-Aug-11 3:56am    
Nope am not disposing any where..its extremely simple code i have it

namespace DataGridPaging
{
public partial class Login : Form
{


public Login()
{
InitializeComponent();
}
//Main method
static void Main()
{
Application.Run(new Login());

}

//Login button click validation
private void btnSubmit_Click(object sender, EventArgs e)
{
string username=txtUserName.Text.ToString();
string pass = txtPass.Text.ToString();
if (username == "test")
{
Login logform = new Login();

//Login successful then navigate to Form2.
DbNavigate.frmDataGridPaging form = new DbNavigate.frmDataGridPaging();
form.ShowDialog();



}
else
{
MessageBox.Show("Login Failed");
}
}
shan1395 11-Aug-11 3:57am    
namespace DataGridPaging
{
public partial class Login : Form
{


public Login()
{
InitializeComponent();
}
//Main method
static void Main()
{
Application.Run(new Login());

}

//Login button click validation
private void btnSubmit_Click(object sender, EventArgs e)
{
string username=txtUserName.Text.ToString();
string pass = txtPass.Text.ToString();
if (username == "test")
{

this.Close();
//Login successful then navigate to Form2.
DbNavigate.frmDataGridPaging form = new DbNavigate.frmDataGridPaging();
form.ShowDialog();
}
else
{
MessageBox.Show("Login Failed");
}
}
Praveen Kullu 11-Aug-11 5:26am    
You could do with this.Hide() instead of this.Close().
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900