A
archie456
Guest
Hi,
I’m new to Visual Studio and have an issue with Forms and partial classes.
I have a form with has a lot of code behind it. To make it easier to navigate I’ve created a new C# file and put in it the partial class for the form, I’ve then moved some of the forms routines I created into the new c# file.
The problem with this is that when I add the partial class to the new c# file, the c# file then open another form when I double click on it – so now I have two forms??
This is the process I’m taking:
“Public partial class Form1 : Form” from Form1.cs and replace the line “class Class1” in Class1.cs
I also add “Using System.Windows.Forms” to Class1.cs.
So I now appear to have two forms in my project, the original one for Form1.cs and the new blank one for Class1.cs.
The main reason I am doing this is because the code I have in Form1 is becoming very long and difficult to navigate and so I’d like to split the code into different files. From a previous post on the internet someone said that partial classes where the best way of doing this.
I'd appriciate some advise on why I'm getting two forms - its not a big deal as I can still run my code, its just confusing...
Thanks.
Continue reading...
I’m new to Visual Studio and have an issue with Forms and partial classes.
I have a form with has a lot of code behind it. To make it easier to navigate I’ve created a new C# file and put in it the partial class for the form, I’ve then moved some of the forms routines I created into the new c# file.
The problem with this is that when I add the partial class to the new c# file, the c# file then open another form when I double click on it – so now I have two forms??
This is the process I’m taking:
- Create a new solution, and add a form – Called Form1 (I’ve added a button to the form).
- As my form has a lot of code, I would like to create a partial class of Form1 so that I can put some of the code in a different file – its easier to navigate this way (so I'm told), so I add a new Class which creates Class1.cs
- To change Class1 to a partial class of Form1, I copy the code:
“Public partial class Form1 : Form” from Form1.cs and replace the line “class Class1” in Class1.cs
I also add “Using System.Windows.Forms” to Class1.cs.
- Now when I double click on Class1.cs it open a blank form (though I can get to the code by double clicking on the blank form).
So I now appear to have two forms in my project, the original one for Form1.cs and the new blank one for Class1.cs.
The main reason I am doing this is because the code I have in Form1 is becoming very long and difficult to navigate and so I’d like to split the code into different files. From a previous post on the internet someone said that partial classes where the best way of doing this.
I'd appriciate some advise on why I'm getting two forms - its not a big deal as I can still run my code, its just confusing...
Thanks.
Continue reading...