Click here to Skip to main content
15,917,793 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
C#
private void btnsearch_Click(object sender, EventArgs e)
        {
            Form2 newform = new Form2();
            this.Hide();
            Form2.ShowDialog();
            this.Show();
}



This is not worked for me

I found an error as
An object reference is required for the non-static field, method, or property 'System.Windows.Forms.Form.ShowDialog()

Can anyone pls help to this?
Posted

C#
private void Button1_Click(Object sender, EventArgs e )
{
   var myForm = new Form1();
   myForm.Show();
}

This will work.
 
Share this answer
 
Form2 newform = new Form2();
           this.Hide();
           newform.ShowDialog();
           this.Show();
 
Share this answer
 
Comments
Asa code 9-Jan-14 2:16am    
this worked well for my problem..... thanks...:)
Karthik_Mahalingam 9-Jan-14 2:18am    
welcome Asa code :)
Praveen_P 9-Jan-14 3:46am    
5 !
Karthik_Mahalingam 9-Jan-14 4:05am    
thanks praveen :)
You should use the name you assigned to the Form
C#
private void btnsearch_Click(object sender, EventArgs e)
        {
            Form2 newform = new Form2();
            this.Hide();
            newform.ShowDialog();
            this.Show();
}
 
Share this answer
 
Comments
Karthik_Mahalingam 9-Jan-14 2:18am    
5,correct

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