views:

141

answers:

1

New to VS2008...

I am using CLR Forms to create a GUI. I put a button on the form and then ask the IDE to create a click event. VS2008 puts the code in the .h file and formats it 'badly' compared to our in-house guidelines.

How do i get the code into the .cpp file and format it correctly?

Worse, when I 'reset' the event, VS2008 does not remove the generated code if I did any edits in it!

+1  A: 

The managed code tools are mainly written for managed languages and in managed languages there is no header file so everything is in the source file. To port it to C++ it would be easier to just change file extension than to write the code to split generated code into header files and source files

Try the Edit.FormatDocument command (default shortcut CTRL + K, CTRL + D). The modification is limited by the settings specified on the Formatting pane of the C++ language in the Text Editor section of the Options dialog box. You can also use Edit.FormatSelection (ALT + F8 CTRL + K, CTRL + F) after selecting what you want to format. ActiveDocument.Selection.SmartFormat may work too, but I don't know its shortcut. You can create a macro/addin to call it.

There are other tools that can provides better control in formating the current file and some can be even used as external tools or add-ins in Visual Studio. Search "code beautifier visual C++" or "code formatting visual C++" in your favorite search engine to find them.

Sheng Jiang 蒋晟
Edit.FormatDocument does not change the formatting. The formatting options in the C++ editor option dialog are very limited.Is it standard for the IDE to put code into the .h?
gbrandt
see the edited post.
Sheng Jiang 蒋晟
Code beautification is only half the answer. VS2008 also puts the code into the .h file, not the .cpp file. Which is maybe a great idea for C#, but not for C++. Thanks though!
gbrandt