Resolved Finding my code that I wrote

357mag

Well-known member
Joined
Mar 31, 2023
Messages
58
Programming Experience
3-5
I've written several GUI programs using Visual C# and Visual Studio 2015. I downloaded Visual Studio 2022 just out of curiosity and I loaded one of my projects and I could not find in Solution Explorer the file that held the code that I wrote for the project. I can click on everything in Solution Explorer and still not see the code I wrote for the project.

What I had to do was click on Form1.cs to bring up the Form I was working with, and then I had to double-click the Run button that I made and placed on the Form. When I double-clicked the Run button then I was brought to the code window where I entered the code for the program.

I don't understand why I had to do that.

Shouldn't I have been able to choose the code source file in Solution Explorer on the right side and get right to the code window where I typed in my code? I don't get it. Why the code is kinda hidden.
 
Solution
That screenshot looks mostly correct. The Form1.cs node in the Solution Explorer represents both the designer and the code and you should be able to open both from that. Double-clicking it will always open the designer. What does look odd is that there appears to be a button missing from the Solution Explorer toolbar. The spanner icon is for Properties and there should be another icon to the left of that showing angled brackets for View Code. That appears to be missing in your case. Whether that means that you can't open the code window at all or it's just a missing button is the question. If you right-click that Form1.cs node, is there a View Code option in the menu? If you click the node and press F7, does that open the code for the...
Here is a screenshot:
 

Attachments

  • Visual Studio Screenshot.jpg
    Visual Studio Screenshot.jpg
    256.7 KB · Views: 11
That screenshot looks mostly correct. The Form1.cs node in the Solution Explorer represents both the designer and the code and you should be able to open both from that. Double-clicking it will always open the designer. What does look odd is that there appears to be a button missing from the Solution Explorer toolbar. The spanner icon is for Properties and there should be another icon to the left of that showing angled brackets for View Code. That appears to be missing in your case. Whether that means that you can't open the code window at all or it's just a missing button is the question. If you right-click that Form1.cs node, is there a View Code option in the menu? If you click the node and press F7, does that open the code for the form? Along with that button, those are the normal ways to open the code window. You can also use F7 when you have the form open in the designer.

If you can't use those options, try creating a new WinForms project - make sure you create one to target .NET Framework, although it's worth testing .NET (Core) too - and see if you get those options in that case. If you do then it's presumably related to the fact that it's an old, upgraded project. If you don't then maybe VS is broken and you may need to do a repair.
 
Solution
Shouldn't I have been able to choose the code source file in Solution Explorer on the right side and get right to the code window where I typed in my code?

No, not for a form. Double clicking on a form cs file in the solution explorer opens the form designer. Right clicking on the file and choosing View Code from the popup menu is what opens the code view of it. There are other ways, as you have found, and you can also right click on the background of the form designer and choose to go to the code
 
That screenshot looks mostly correct. The Form1.cs node in the Solution Explorer represents both the designer and the code and you should be able to open both from that. Double-clicking it will always open the designer. What does look odd is that there appears to be a button missing from the Solution Explorer toolbar. The spanner icon is for Properties and there should be another icon to the left of that showing angled brackets for View Code. That appears to be missing in your case. Whether that means that you can't open the code window at all or it's just a missing button is the question. If you right-click that Form1.cs node, is there a View Code option in the menu? If you click the node and press F7, does that open the code for the form? Along with that button, those are the normal ways to open the code window. You can also use F7 when you have the form open in the designer.

If you can't use those options, try creating a new WinForms project - make sure you create one to target .NET Framework, although it's worth testing .NET (Core) too - and see if you get those options in that case. If you do then it's presumably related to the fact that it's an old, upgraded project. If you don't then maybe VS is broken and you may need to do a repair.

There is a View Code (F7) option there which appears to be working okay.
 
Back
Top Bottom