views:

226

answers:

2

If I create a new form called myForm, the top of myForm.h looks like this:

#pragma once

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;     //<<<< THIS ONE
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

None of these are even needed, because the wonderful forms designer always fully-qualifies its objects.

The one marked with THIS ONE is particularly annoying because it breaks my build. This is because I use the generic form of IList all over the place - I love it so much that I put it in stdafx.h, like this:

using System::Collections::Generic::IList;

So then if I want to use myForm from any other file where I happen to use IList, like this:

#include "StdAfx.h"
#include "ABC.h"
#include "myForm.h"

ABC::ABC()
{
    IList<int>^ myList;
    ...
}

then it fails to compile:

1>.\ABC.cpp(7) : error C2872: 'IList' : ambiguous symbol
1>        could be 'c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::Collections::Generic::IList'
1>        or       'c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::Collections::IList'
1>.\ABC.cpp(7) : error C2872: 'IList' : ambiguous symbol
1>        could be 'c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::Collections::Generic::IList'
1>        or       'c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : System::Collections::IList'

So, how can I stop a new form from adding all these useless and destructive usings?

+2  A: 

You can modify Form Template of Visual Studio. For further reading, take a look at:

http://msdn.microsoft.com/en-us/library/ms185319(VS.80).aspx

Boris Modylevsky
Sorry I don't see where it applies to forms - it only seems to talk about projects. Could you explain how to use this method to change the form template?
demoncodemonkey
Item templates should be located at:"C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\VisualC\1033"However it's recommended create your own custom form template, rather than modifying a default one. You can find instructions on how to create your own template right here:http://www.dev102.com/2008/07/24/visual-studio-item-templates/
Boris Modylevsky
Thanks but in this case I did actually want to modify the default one. Why would you say it's recommended to create a custom one?
demoncodemonkey
Custom template are stored in My Document folder and can be backed up. It's easier to restore your machine after reinstalling of VS, or sending this template to your colleagues.
Boris Modylevsky
+2  A: 

You can change the default templates that Visual Studio uses by editing the zip files in the ItemTemplates directory for the specific language that you use.

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033

is where the C# templates are. I'm assuming the C++ templates would be in a similar directory but I don't have a VS instance installed with C++ handy.

womp
VC ones are in: C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\VisualC\1033 however there are only 4 zipfiles - HelpTest, OrderedTest, SimpleUnitTest and UnitTestWizard. No Form.zip or anything remotely useful :(
demoncodemonkey
Huh. Interesting. Well this directory seems promising: C:\Program Files\Microsoft Visual Studio 9.0\VC\vcprojectitems\Code ... except that the code.vsdir file seems to be pointing to some registry keys... let me follow them...
womp
http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvc/thread/86b9d540-376f-4cb7-bd4f-f401e0fba7b3 seems to be in the right direction. Not sure if editing the "hfile.h" would solve your issue though.
womp
You almost got it, I'm gonna accept your answer. I found a file called newform.h and removed the annoying using from it, so now any new forms do not have that in. Thanks! C:\Program Files\Microsoft Visual Studio 9.0\VC\VCWizards\CodeWiz\.NET\WinForm\Templates\1033\newform.h
demoncodemonkey