Now that C++ development has become second nature to me, do I have to start from scratch with C#? What used to be called a "dialog" or a "window" seems to now be called a "form". Is this right?
Since the beginning of Visual Studio, there has been easy way to describe the shape of a Dialog (now called a Form) in the resource file and then use a wizard to create the corresponding C++ code. I kind of remember that in MFC it was pretty much a no-brainer to create a custom dialog with all the components you want and then all the associated code.
If I have a C# app that has many forms that I want to bring to the screen based on the user's menu selections, how do I create a class associated with a windows form?
Loading

Sam HobbsPosted Apr 18, 2010, 2:49 PM
As has already been said, just try creating a Forms application; you will see that code is auatomatically generated. Note that for each generated form, there is a desing view and a code view. Also for each generated form, there is a design.cs file. You can write code that creates a form in execution and the genrated design.cs file has the code in it that is the code you would write yourself if you were to do it all yourself. So you can look at the design.cs file to see how to do things yourself if you want to. Unlike MFC, we don't have the source code for .Net. Also, unlike the Windows API, forms are not stored in a binary file (such as a .res file) that gets put into the program's resources; forms get created from code that we can see, even generated forms. In many ways, forms are easier; the stuff that the Class Wizard did for MFC is now done automatically for forms.
One thing that is not supported by VS as much as it was for MFC is the use of controls derived from other controls. At least, it is not so obvious. In a forms application, you can add event handlers for controls in a form and the event handlers get generated in the form class. It is however totally possible to derive a class from another control class, such as ComboBox or TreeView or TextBox and then use the derived class control in a form. Also, it is possible to easily create UserControls that are like subforms that have multiple controls in them and can be added to forms as controls.
I am not sure about subclassing; I think that subclassing is sometimes easier in .Net and sometimes more difficult. I don't know about message reflection and the routing of messages such as that. Generally speaking, .Net makes many things easier, but if we want to do things that it does not make easier, it is likely more difficult to do using .Net than using MFC.
I have been using Visual C++ since version 1, before it was called Visual Studio. I used the Microsoft C compiler before it was "Visual" and before it supported C++. It even supported OS/2 for a few years. You can see some of what I know about MFC in my MFC.
Mahesh ChandPosted Apr 18, 2010, 12:43 PM
Have you created this application in Visual Studio? Each Form class (with UI) has a code-behind class related to the UI. Code-behind class has all the code. Let's say, you have a Form called, MyForm. If you F7 on that, you will see a class MyForm derived from Form class.
If you want to call this Form when application starts, you have to create an instance of this and call Show method. I think by default, Main Form is your startup application. This is how you can do:
MyForm frm = new MyForm();
frm.Show();
Jaish MathewsPosted Apr 18, 2010, 11:47 AM
Class already created, once your winform GUI generated.To see the class, load your winform GUI in design view and press F7