Form
-
I have created 2 forms namely form1.cs and form2.cs.... I want to move from one form to another at the run time with a click of a button...The following code gives me an error... Error 1 The type or namespace name 'Form2' could not be found (are you missing a using directive or an assembly reference?) Is there any other method of doing it..
public class Form1:System.Windows.Forms.Form
{
public Form2 i;
}private void button1_click(object sender,System.EventArgs e)
{
i=new Form2();
i.ShowDialog();
} -
I have created 2 forms namely form1.cs and form2.cs.... I want to move from one form to another at the run time with a click of a button...The following code gives me an error... Error 1 The type or namespace name 'Form2' could not be found (are you missing a using directive or an assembly reference?) Is there any other method of doing it..
public class Form1:System.Windows.Forms.Form
{
public Form2 i;
}private void button1_click(object sender,System.EventArgs e)
{
i=new Form2();
i.ShowDialog();
} -
I have created 2 forms namely form1.cs and form2.cs.... I want to move from one form to another at the run time with a click of a button...The following code gives me an error... Error 1 The type or namespace name 'Form2' could not be found (are you missing a using directive or an assembly reference?) Is there any other method of doing it..
public class Form1:System.Windows.Forms.Form
{
public Form2 i;
}private void button1_click(object sender,System.EventArgs e)
{
i=new Form2();
i.ShowDialog();
}do you want to just display form 2 temporarily (as you have used .ShowDialog()) or do you want to completely switch forms (i.e. hide the first and show the second)?
If only MySelf.Visible was more than just a getter... A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting
-
do you want to just display form 2 temporarily (as you have used .ShowDialog()) or do you want to completely switch forms (i.e. hide the first and show the second)?
If only MySelf.Visible was more than just a getter... A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting
-
ok here is my suggestion for you to think about: Create a static class that holds form instances i.e.
Form1 form1 = new Form1;
Form2 form2 = new Form2;
Form3 form3 = new Form3;
...Create a private static function for hiding all the forms i.e.
private static void HideAll()
{
if(form1 != null && !form1.Disposed && form1.Visible)
form1.Hide();
...
}Next create a public static function for displaying the desired form i.e.
public static void ShowForm(int formNum)
{
HideAll();
switch(formNum)
{
case 1:
form1.Show();
break;
...
}
}Then whenever you handle a button click you can do...
StaticForm.ShowForm(1);//to show Form1 only
If only MySelf.Visible was more than just a getter... A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting
-
I have created 2 forms namely form1.cs and form2.cs.... I want to move from one form to another at the run time with a click of a button...The following code gives me an error... Error 1 The type or namespace name 'Form2' could not be found (are you missing a using directive or an assembly reference?) Is there any other method of doing it..
public class Form1:System.Windows.Forms.Form
{
public Form2 i;
}private void button1_click(object sender,System.EventArgs e)
{
i=new Form2();
i.ShowDialog();
}This is a message from the compiler telling you that it can't find the definition of Form2 in your code. You probably just need to qualify the name so that the compiler can locate Form2. If Form2 was not defined in the current namespace then you should either qualify the declaration of i with the namespace where Form2 was defined. e.g. public mynamespace.Form2 i; or insert a using directive at the top of the file e.g. using mynamespace; Alan.
-
This is a message from the compiler telling you that it can't find the definition of Form2 in your code. You probably just need to qualify the name so that the compiler can locate Form2. If Form2 was not defined in the current namespace then you should either qualify the declaration of i with the namespace where Form2 was defined. e.g. public mynamespace.Form2 i; or insert a using directive at the top of the file e.g. using mynamespace; Alan.
This is the code i used in form1.cs: But still im not able to move to form2.cs
using WindowsApplication8;
public partial class Form1 : Form
{
WindowsApplication8.Form2 f2;
}private void ll_linkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
//System.Diagnostics.Process.Start("Form2.cs");
//f2 = new Form2();
//f2.showDialog();f2 = new WindowsApplication8.Form2(); //f2.Activate(); f2.Show(); }
-
I have created 2 forms namely form1.cs and form2.cs.... I want to move from one form to another at the run time with a click of a button...The following code gives me an error... Error 1 The type or namespace name 'Form2' could not be found (are you missing a using directive or an assembly reference?) Is there any other method of doing it..
public class Form1:System.Windows.Forms.Form
{
public Form2 i;
}private void button1_click(object sender,System.EventArgs e)
{
i=new Form2();
i.ShowDialog();
}you should use an IntPtr variable in form2 to hold the Handle of form1 :
public partial class Form1 : Form { Form2 form2; public Form1() { InitializeComponent(); form2 = new Form2(this.Handle); } private void button1\_Click(object sender, EventArgs e) { this.Hide(); form2.Show(); } }
and
public partial class Form2 : Form { private IntPtr friendHandle; public Form2(IntPtr hnd) { InitializeComponent(); friendHandle = hnd; } private void button1\_Click(object sender, EventArgs e) { this.Hide(); Form.FromHandle(friendHandle).Show(); } }
this works fine. i tried if you want to the information in the forms to be saved you souldn't make a new instance of forms in click event but if you don't need them then you are free to do it :laugh:
sometimes 0 can be 1
-
This is the code i used in form1.cs: But still im not able to move to form2.cs
using WindowsApplication8;
public partial class Form1 : Form
{
WindowsApplication8.Form2 f2;
}private void ll_linkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
//System.Diagnostics.Process.Start("Form2.cs");
//f2 = new Form2();
//f2.showDialog();f2 = new WindowsApplication8.Form2(); //f2.Activate(); f2.Show(); }
mrithula8 wrote:
This is the code i used in form1.cs: But still im not able to move to form2.cs
Hmm, ok. You do understand that there are two quite distinct steps in programming an application? 1) Write the code and then build the application using the compiler 2) Test and debug the application All the problems you are having stem from the fact that the code you have written will not compile. There are quite a few mistakes in your code and I think it would be useful for you to review the online help information on MSDN. Here is a good link demonstrating how to show a form. http://msdn.microsoft.com/en-us/library/aa984358(VS.71).aspx[^] The correct code based on the limited information you have given should be as shown below. This will start Form2 as a modal dialog. Note that I've moved the event handler inside the Form1 class definition as the code was never going to compile the way you had it arranged.
using System;
using WindowsApplication8;
using System.Windows.Forms;public partial class Form1 : Form {
Form2 f2;private void ll_linkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
f2 = new Form2();
f2.ShowDialog();
}
}[Edit: Oops, corrected typo in my supposedly correct code!] Alan.
modified on Thursday, February 12, 2009 9:36 AM