C++/CLI,Winforms:VS2008 中子文件夹下的新表单
当我在 C++/CLI Winforms 项目中的 VS2008 的子文件夹下创建新表单时,.h 和 .cpp 会在子文件夹下正确创建。但是,当在设计器中打开表单并更改标题时,我收到一条错误消息,指出 .resx(在此特定时刻擅离职守)已经是项目的一部分。然后可以在解决方案的根文件夹中找到 .resx。我该如何解决这个问题? (...不必向 MS 提交错误,因为这是 VS2010 赛季,他们不会太认真地对待这个问题)
一种选择是在项目的根文件夹中创建表单,然后移动所有三个文件(.cpp 、.h 和 .resx) 到所需的子文件夹,一旦完成所有更改。在这种情况下,我发现一旦表单移动到子文件夹,“视图设计器”就不再可用。
救救我。请。我没有做任何值得这样的事情。
When I create a new form under a sub-folder in VS2008 in a C++/CLI Winforms project, the .h and .cpp are correctly created under the sub-folder. However, when the form is opened in the designer and the title is changed, I get an error message saying that the .resx (AWOL till this particular moment) is already part of the project. One can then locate the .resx in the root folder of the solution. How do I get around this? (...without having to file a bug with MS who aren't gonna take this too seriously since this is the VS2010 season)
One option would be to create the form in the project's root folder and then move all three files (.cpp, .h and .resx) to the desired sub-folder once all changes have been made. In this case, I find that "View Designer" is no longer available once a form has been moved to a sub-folder.
Save me. Please. I have done nothing to deserve this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这符合我的医生通常的建议:如果疼,就不要做。 C++ IDE 不够智能,无法在正确的文件夹中创建 .resx。不过它是可以修复的。当出现错误消息框时,切换到资源管理器并将刚刚创建的 .resx 文件从项目目录移动到您自己的子目录。切换回来并点击“确定”,之后一切似乎都正常工作。
This fits my doctor's usual advice: if it hurts, don't do it. The C++ IDE isn't smart enough to create the .resx in the correct folder. It is fixable though. When you get the error message box, switch to Explorer and move the just created .resx file from the project directory to the subdirectory yourself. Switch back and hit OK, everything appears to work correctly after that.
汉斯的回答是正确的,但并没有完全解决我的问题。
我希望我的源(.cpp、.h,甚至 .resx)文件位于子目录(“SourceCode”)中,而不是与项目文件夹中的所有混乱混合在一起。 VS 使将表单 (Form1) 移出项目目录变得困难 - 您可以移动 .h 和 .resx 文件(在 Windows 资源管理器中)并将它们添加(在 Soln 资源管理器中)作为现有项目,但 VS 不会这样做t 将它们识别为表单。我找不到一种方法来告诉 VS form.h 文件是表单项的一部分(有办法吗?)
我找到了解决方法:右键单击头文件(在解决方案资源管理器中)->添加-> ;新项目->Windows 窗体。浏览到源代码子目录并将表单命名为 (myForm)。然后,从原始 form1.h 文件复制源代码并将其粘贴到新 myForm.h 中的源代码上。对 form1.cpp / myForm.cpp 文件执行相同的操作。另外,在所有项目文件中进行全局搜索并将旧表单名称 (Form1) 替换为新表单名称 (myForm)(如果您更改了表单名称)。此时,您可以在解决方案资源管理器中删除原始 form1.h 和 form1.cpp(但在确定新版本一切正常之前不要删除这些文件)。
这似乎有效,但起初我在解决方案资源管理器中的 myForm.h 下没有看到 myForm.resx 文件。在新表单(myForm)中重新排列控件后,我收到“.resx 已经是项目的一部分”消息。消息框不会接受“确定”作为答案。我在子文件夹中看到了 myForm.resx 文件(?),但我注意到项目文件夹中也有一个。我想我删除了项目文件夹中的那个。然后 Soln Explorer 中有两个 myForm.resx 文件(两个 .resx 文件具有相同的名称)。不知何故,我确定第一个对应于项目文件夹,然后将其删除。现在一切正常。
顺便说一句,我正在使用 VS2010。我希望我的工作也适用于 VS2008。当表单崩溃时(这种情况经常发生),我在 VS2003 中使用了类似的技巧。
Hans answer is right on, but didn't solve my problem entirely.
I want my source (.cpp, .h, even the .resx) files to be in a subdirectory ("SourceCode"), and not mixed in with all the mess in the project folder. VS makes it hard to move the Form (Form1) out of the project directory -- you can move the .h and .resx files (in Windows Explorer) and add them (in Soln Explorer) as existing items, but then VS doesn't recognize them as a Form. I could not find a way to tell VS that the form.h file was part of a Form item (is there a way?)
I found a work around: right click on Header Files (in Solution Explorer)->Add->New Item->Windows Form. Browse to the source code subdirectory and name the form (myForm). Then, copy the source code from the original form1.h file and paste it over the source in the new myForm.h. Do the same for form1.cpp / myForm.cpp file. Also, do a global search and replace from the old form name (Form1) to the new one (myForm) in all project files (if you changed the form name). At this point you can remove the original form1.h and form1.cpp in Solution Explorer (but don't delete the files until you are sure all is well with the new versions).
This seemed to work, but at first I didn't see a myForm.resx file under myForm.h in solution explorer. After rearranging the controls in the new form (myForm) I got the ".resx is already part of the project" message. The message box just wouldn't take OK for an answer. I saw myForm.resx file in the subfolder(?), but I noticed that there was also one in the project folder. I think I deleted the one in the project folder. There were then two myForm.resx files in Soln Explorer (both .resx files had the same name). Somehow I determined that the first one corresponded to the project folder, and I removed it. Now all is working fine.
BTW, I'm working with VS2010. I expect that my work around will also apply to VS2008. I used a similar trick with VS2003 when a form would crash (which was often).