VS 2008的设计师和用户控件 [英] VS 2008 designer and usercontrol
问题描述
我创建了一个自定义数据网格控件。我一拖再拖窗口的形式,并设置其属性,如列,所有与放大器;跑项目。它成功地建立,我能够查看窗体上的网格控件。
现在,如果我尝试查看窗体设计器中,我得到下面的错误..
对象引用不设置到对象的实例。
此错误的实例(1)
1.隐藏调用堆栈
在Microsoft.VisualStudio.Design.Serialization.$c$cDom.XML.$c$cDomXmlProcessor.GetMemberTargetObject(XmlElementData xmlElementData,字符串和放大器;会员)
在Microsoft.VisualStudio.Design.Serialization.$c$cDom.XML.$c$cDomXmlProcessor.CreateAssignStatement(XmlElementData XMLELEMENT)
在Microsoft.VisualStudio.Design.Serialization.$c$cDom.XML.$c$cDomXmlProcessor.XmlElementData.get_$c$cDomElement()
在Microsoft.VisualStudio.Design.Serialization。codeDom.XML。codeDomXmlProcessor.EndElement(字符串preFIX,字符串名称,字符串骨灰盒)
在Microsoft.VisualStudio.Design.Serialization。codeDom.XML。codeDomXmlProcessor.Parse(XmlReader的读者)
在Microsoft.VisualStudio.Design.Serialization。codeDom.XML。codeDomXmlProcessor.ParseXml(字符串xmlStream,codeStatementCollection statementCollection,字符串文件名,字符串方法名)
在Microsoft.VisualStudio.Design.Serialization.$c$cDom.VS$c$cDomParser.OnMethodPopulateStatements(Object发件人,EventArgs五)
在系统,codeDOM。codeMemberMethod.get_Statements()
在System.ComponentModel.Design.Serialization.Type$c$cDomSerializer.Deserialize(IDesignerSerializationManager经理,codeTypeDeclaration声明)
在System.ComponentModel.Design.Serialization.$c$cDomDesignerLoader.PerformLoad(IDesignerSerializationManager经理)
在Microsoft.VisualStudio.Design.Serialization.$c$cDom.VS$c$cDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
在Microsoft.VisualStudio.Design.Serialization.$c$cDom.VS$c$cDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload)
如果我忽略了的异常,形态出现,上面有网格控制的迹象空白。不过,我可以看到code网格在设计文件中。
在这个任何指针将是一个很大的帮助。
我已经定制的网格为我定制要求像我已经添加自定义的文本框中N所有。我定义了3个构造
公共GridControl()
公共GridControl(的IContainer容器)
保护GridControl(SerializationInfo中的信息,的StreamingContext上下文)
我有这个问题所有的时间......它吮吸。
[漫步(上)]
下面是我想我知道:
- 在设计时在窗体上放置控件。建立和刷新often..this会让你知道什么样的变化导致了设计师BARF。
- 在关闭Visual Studio中一路的重新开启....我不能告诉你多少次,我都追一个设计师的错误,这是设计师被套牢。
- 您了解这一点非常重要:设计师是真的,真的很愚蠢......像袋子岩石愚蠢的
-
自定义对象类型的任何公共字段或属性几乎总是导致设计混乱*。我发现下面的属性将清除了大部分的这些问题:
[可浏览(假)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
-
公共字段或属性没有默认的构造函数总会引起设计师的困惑。当你把一个用户控件的窗体设计器有效地创建任何公开的对象需要一个明确的创建路径的control..so。我发现,解决这个问题的最简单的方法(破解版阅读)是保持不平凡的自定义类的私有和公开为门面公共属性。
- ?我说重新启动Visual Studio,因为有时设计师是卡上不存在错误。我希望我做到了。
[漫步(关)]
我希望一些这方面的帮助。
*设计师的困惑:而不是显示你控制的设计显示了一个无用的错误消息,可能会或可能不包括可怕的警告,这是保护您免受code的损失......等等,等等。
I have created a custom data grid control. I dragged it on windows form and set its properties like column and all & ran the project. It built successfully and I am able to view the grid control on the form.
Now if i try to view that form in designer, I am getting following error..
Object reference not set to an instance of an object.
Instances of this error (1)
1. Hide Call Stack
at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.GetMemberTargetObject(XmlElementData xmlElementData, String& member)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.CreateAssignStatement(XmlElementData xmlElement)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.XmlElementData.get_CodeDomElement()
at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.EndElement(String prefix, String name, String urn)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.Parse(XmlReader reader)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.ParseXml(String xmlStream, CodeStatementCollection statementCollection, String fileName, String methodName)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomParser.OnMethodPopulateStatements(Object sender, EventArgs e)
at System.CodeDom.CodeMemberMethod.get_Statements()
at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload)
If I ignore the exception, form appears blank with no sign of grid control on it. However I can see the code for the grid in the designer file.
Any pointer on this would be a great help.
I have customized grid for my custom requirements like I have added custom text box n all. I have defined 3 constructors
public GridControl()
public GridControl(IContainer container)
protected GridControl(SerializationInfo info, StreamingContext context)
I have this problem all the time...it sucks.
[Ramble(on)]
Here is what I think I know:
- When designing place the control on a form. Build and refresh often..this will let you know what change caused the designer to barf.
- Close visual studio all the way an re-open....I cannot tell you how many times I have chased a designer error that was the designer being "stuck".
- It is very important that you understand : The designer is really, really stupid...like bag of rocks stupid.
Any public fields or properties of custom object types will almost always cause designer confusion*. I find the following attributes will clear up most of these problems:
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
Public fields or properties without a default constructor will always cause designer confusion. When you drop a user control on a form the designer effectively creates the control..so any public object needs a clear creation path. I have found that the easiest way around this (read hack) is keeping the non-trivial custom classes private and expose public properties as a facade.
-- Did I say restart visual studio because sometimes the designer is "stuck" on an error that doesn't exist ?..I hope I did.
[Ramble(off)]
I hope some of this helps..
*designer confusion: Instead of showing your controls the designer shows you a useless error message that might or might not include the dire warning that it is protecting you from code loss...blah, blah.
这篇关于VS 2008的设计师和用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!