何解决VS2010在设计模式下打开Windows窗体时需要关闭问题? [英] Ho to solve VS2010 needs to close problem when opening a Windows form in design mode?

查看:92
本文介绍了何解决VS2010在设计模式下打开Windows窗体时需要关闭问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..



我正在使用C#开发桌面应用程序,我是这个开发的新手。我在VS2010中有一个解决方案,包括3个项目(启动项目和其他两个项目)。当我在启动项目中以设计模式打开主窗体时,窗口会提示并包含消息MS Visual Studio遇到问题并需要关闭。,而在同一解决方案的其他窗体中,我可以打开它在设计模式下,错误不会出现。只有在设计模式下打开主窗体时才会出现错误。



即时调试器说denenv.exe中发生了未处理的win32例程。怎么可能只在这个项目中出现这个问题。在我的其他桌面应用程序开发项目中,不会出现此问题。



有关此问题的任何建议或解决方案吗?



提前谢谢..

解决方案

请注意设计模式,不要过度使用它。我通常只定义一般布局,在代码中添加所有其他细节。然后,出现问题,在设计模式下不调用此代码。



有一种简单的技术可以避免这种复杂化。如果代码的某些部分可能在设计器模式下调用,则将其置于if检查 System.ComponentModel.Component.DesignMode

http://msdn.microsoft。 com / en-us / library / system.componentmodel.component.designmode%28v = vs.110%29.aspx [ ^ ]。



换句话说,通过这样做可以避免麻烦:

  if (DesignMode) {
// 一些有问题(未经测试)或任何其他可能引发异常的代码
}





有时候,问题不会在正常的应用程序执行中暴露出来,但是当你在用某种形式或用户控件打开设计师。将此检查添加到代码片段中,直到表单开始在设计时显示。这样,您就可以找到问题所在。之后,你可以解决问题;您可能希望保留if块或在修复后将其删除,具体取决于所需的设计时功能。但同样,请保持简单,不要过度使用它,特别是如果您不是设计师应该由其他开发人员使用的组件提供商。



< DD> -SA


Hi to all..

I am developing a desktop application using C# and I am novice of this development. I have a Solution in VS2010 that consist of 3 projects (Startup project, and two other projects). When I open the Main form in design mode in my Startup project, a window prompts and contains a message "MS Visual Studio has encountered a problem and needs to be closed.", while in the other forms in the same Solution I can open it in design mode and the error doesn't appears. The error only appears when I open my main form in design mode.

The Just-In-Time Debugger says "An unhandled win32 exeption occurred in denenv.exe". How could this be possible that this problem occurs only in this project only. While in my other desktop application development Projects, this problem doesn't occurs.

Any suggestions or solution about this problem?

Thank you in advance..

解决方案

Just be careful with design mode, don't overuse it. I normally only define general layout, adding all other detail in code. Then, is something goes wrong, this code is not called in design mode.

There is one simple technique of avoiding such complication. If some part of your code can possibly been called in the designers mode, put it under "if" checking for System.ComponentModel.Component.DesignMode:
http://msdn.microsoft.com/en-us/library/system.componentmodel.component.designmode%28v=vs.110%29.aspx[^].

In other words, stay away of trouble by doing this:

if (DesignMode) {
    // some questionable (un-tested) or any other potentially exception-throwing code
}



Sometimes, the problem is not exposed in normal application execution, but still is manifested when you open a designer with some form or user control. Add this checks to pieces of your code until the form begins showing in design time. This way, you can locate the problem. After that, you can fix the problem; you may want to leave the "if" block as is or remove it after the fix, depending on required design-time functionality. But again, keep it simple, don't overuse it, especially if you are not a provider of components which should be used by other developers under the designer.

—SA


这篇关于何解决VS2010在设计模式下打开Windows窗体时需要关闭问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆