当我将用户控件拖到Form中时,VS2008退出了? [英] Vs2008 is out when I drag my usercontrol into Form?

查看:57
本文介绍了当我将用户控件拖到Form中时,VS2008退出了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户控件(链接: http://www.mediafire.com/?h635lk4fazr9e7z ),我没有我不明白我不能将其拖到窗体中的原因,当我这样做时,VS2008出局了.

I have a usercontrol (link: http://www.mediafire.com/?h635lk4fazr9e7z), I don''t understand what reason that I can''t drag it into my Form, when I do this then VS2008 is out. Please check it to help me, thanks.

推荐答案

请参阅我对问题的评论.

我答应了一个建议...

使用以下工具调查Studio崩溃:将您控件的几乎所有代码都放在此代码块中:
Please see my comment to the question.

I promised one advice…

Use the following tool to investigate the Studio crash: put almost all of your code of your control in this block:
if (!DesignMode) {
   //rendering, setters, and a lot more...
}



请参阅:
http://msdn.microsoft.com/en-us/library/system. componentmodel.component.designmode.aspx [ ^ ].

这样,大多数代码都可以工作,因为它无法工作(我已经对其进行测试,它确实可以以某种方式工作),但是不能在设计模式下工作,这可以防止Studio崩溃.逐一添加您在设计模式下真正需要的一些功能,直到再次崩溃.这样,您将能够找到问题所在.再次,有一个Studio错误,因此您只需要一种解决方法.您的最终结果仍应使用此(!DesignMode)条件-实际上在设计模式下绝不应出现许多内容.

但是首先,我将重新编写代码.

我发现了另一个大问题:您的渲染基于PictureBox.没有任何理由将此控件用于您的目的.它根本对您没有帮助,只会加添麻烦,消耗您的开发时间和资源.此控件完全没有帮助.您应该改用System.Windows.Forms.Control并在覆盖的方法OnPaint中呈现所有内容.这是滥用PictureBox的常见错误.

有关更多详细信息,请参阅我过去的答案:
如何从旧图纸中清除面板 [ ^ ],
在C#中绘制矩形 [在图片框内添加图片 [在mdi子表单之间画线 [在面板上捕获图形 [ Paint是一种哪种好玩的方法? (DataGridViewImageCell.Paint(...)) [



Please see:
http://msdn.microsoft.com/en-us/library/system.componentmodel.component.designmode.aspx[^].

This way, most of the code will work as it works not (I tested it, it does work somehow), but not under design mode, which should prevent Studio crash. Add some functionality feature you really need in design mode one by one until you have the crash again. This way, you will be able to locate the problem. Again, there is a Studio bug, so you just need a workaround. Your final result should still use this (!DesignMode) condition — many things really should never appear in design mode.

But first of all, I would re-write the code.

I found another big problem: your rendering is based on PictureBox. There is no single reason to use this control for the purpose you do. It does not help you at all, only adds up hassles, eats up your development time and resources. This control does not help at all. You should use System.Windows.Forms.Control instead and render everything in the overridden method OnPaint. This is a very usual mistake to abuse PictureBox.

For further detail, please see my past answers:
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^],
Append a picture within picturebox[^],
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^].

—SA


这篇关于当我将用户控件拖到Form中时,VS2008退出了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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