Renaming Windows Forms and Files

G

Guest

These things are rather basic, but I can't seem to find an explanation in
MSDN. I'm using VC++2005 Professional.

1. What steps must I take to rename a form?

I currently select the form in the Class Explorer, and then in the
properties window, I enter a new name under "Name". This seemed to work once
or twice, but after trying a couple of times, the name of the class displayed
by the class explorer does not match what I entered in the properties window.

2. What are the steps for renaming the .h/.cpp/.resx files containing the
code for the form?

It seems like the only way to do this is to select Save As from the file
menu. This will save the files under a new name, but will not change the
file name in the project. I tried to remove the old files, and then add to
the project the files with the new names, but then this brings me to my third
problem.

3. If I removed a form from my project, but then wanted to add it back to
the project, how do I do this such that the .resx file is associated with the
..h file in the solution explorer, the way it is when you initially add a new
form to a project?

Right now, I simply right click on the project name in the solution
explorer, select Add..., and then in the Open dialog, I select the three
files (.cpp/.resx/.h) associated with the form. But VS adds them to the
project as if they have nothing to do with each other. I consequently can't
figure out how to display and modify the form using the form designer.

Is any of this explained in the MSDN somewhere? If so, where?

Thanks for any help on this, and sorry if this message appears twice,
StephenJ
 
K

Kevin Spencer

The name of a class and the Name property of a System.Windows.Forms.Control
class (System.Windows.Forms.Form inherits Control) are 2 completely
different things. In the Visual Studio IDE, if you rename (not save as) a
Form, the class name will be changed to the same name as the file name.

--
HTH,

Kevin Spencer
Microsoft MVP
Computer Control Freak
http://unclechutney.blogspot.com

A man, a plan, a canal, a palindrome that has.. oh, never mind.
 
G

Guest

Kevin Spencer said:
The name of a class and the Name property of a System.Windows.Forms.Control
class (System.Windows.Forms.Form inherits Control) are 2 completely
different things. In the Visual Studio IDE, if you rename (not save as) a
Form, the class name will be changed to the same name as the file name.

I appreciate the reply Kevin, but I still don't understand how to properly
change the name of a form, how to properly rename the files containing the
form, how to properly add the files for forms to projects such that they can
be editted in the designer, and where I can find information on this in MSDN.
Any help with these specific items would be much appreciated.

StephenJ
 
K

Kevin Spencer

To quote myself:

That is how to change the name of the Form class in the IDE, if you want the
class file name to be the same name as the Form. The IDE will refactor all
other references to the Form to use the name you change it to. If you don't
want or need the file name to be the same as the Form name, you can simply
rename the Form in your code. All references to the Form class will also be
updated to reflect the new name.

As for your further questions, first, here's an excellent reference to all
things .Net:

http://msdn2.microsoft.com/en-us/library/default.aspx

I didn't understand this (new?) question:
how to properly add the files for forms to projects such that they can
be editted in the designer

If I understand you correctly (I don't know if I do), you right-click the
Project in the IDE, and select Add, and select "Windows Form" from the
context menu to add another Form to the Project.

--
HTH,

Kevin Spencer
Microsoft MVP
Computer Control Freak
http://unclechutney.blogspot.com

A man, a plan, a canal, a palindrome that has.. oh, never mind.
 
G

Guest

Kevin Spencer said:
I didn't understand this (new?) question:


If I understand you correctly (I don't know if I do), you right-click the
Project in the IDE, and select Add, and select "Windows Form" from the
context menu to add another Form to the Project.

Here, I've done the following:

1. I added a new form to my project. I put some controls on the form, add
some events, and then save this form with the file name MyForm. So now in
this project, there are three files associated with the form: MyForm.h,
MyForm.resx, and MyForm.cpp. The node in the solution explorer for the
MyForm.resx file appears as a child of the MyForm.h file uder the "Header
Files" folder.

2. I then decide not to use this form in the project, so I remove it from
the project. To remove this form from the project, I remove MyForm.h,
MyForm.resx, and MyForm.cpp.

3. Later, I decide I do want to use the form in the project, so now I have
to add it back. To add it back to the project, I right click on the project
in the solution explorer, and then goto Add, and in the next popup menu that
appears, I select Existing Item.... In the open file dialog that appears, I
select the three files for the form, MyForm.h, MyForm.resx, and MyForm.cpp.

When VS adds these three forms, it puts the MyForm.h file under the "Header
Files" folder, the MyForm.resx file under the Resource Files folder, and the
MyForm.cpp file under the Source Files folder. The resx file is not
associated with the .h file, the way it was when I initially added the form
to the project as a new form. Furthermore, when I display the code in
MyForm.h in the editor, there is no way to switch to the form designer for
MyForm, the way there is when the form is initially added to the project.

How do I get VS to display MyForm in the designer? How do I get VS to
recognize that MyForm.h and MyForm.resx go together?

Where is this explained in the MSDN library?

Thanks for your previous answers.

StephenJ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top