【转帖】解决继承窗体或用户控件时“visual继承当前被禁用,因为基类引用设备特定的组件或包含 p/invoke”问题

当自定义控件所在的dll中出现了DllImport 属性时候,自定义类型的控件属性就不能正常显示在属性窗口了

通过将 DesktopCompatible(true) 属性放置在父窗体或父用户控件中,可以安全地启用可视继承

先在项目中添加一个“设计时属性文件”默认名为DesignTimeAttributes1.xmta

然后在其中添加如下节点

<Class Name="SmartDeviceProject1.Form1">  
<DesktopCompatible>true</DesktopCompatible>
</Class>
SmartDeviceProject1.Form1为被继承的类名,

ok,这样应该就能解决问题了

如果自己写的控件类,需要在设计视图中显示内容也可以通过在此文件中添加如下节点:

<Class Name="ImageButton">  
<DesktopCompatible>true</DesktopCompatible>
<Property Name="Size">
<DefaultValue>
<Type>System.Drawing.Size, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Type>
<Value>16, 16</Value>
</DefaultValue>
</Property>
</Class>

这里ImageButton为控件的类名。

 

文章出处:http://blog.csdn.net/sohighthesky/article/details/4249129

posted @ 2011-08-08 16:58  bobbychen  阅读(639)  评论(0编辑  收藏  举报