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

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

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

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

然后在其中添加如下节点

  1. <Class Name="SmartDeviceProject1.Form1">  
  2.   <DesktopCompatible>true</DesktopCompatible>  
  3. </Class>  

 

SmartDeviceProject1.Form1为被继承的类名,

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

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

  1. <Class Name="ImageButton">  
  2.   <DesktopCompatible>true</DesktopCompatible>  
  3.   <Property Name="Size">  
  4.     <DefaultValue>  
  5.       <Type>System.Drawing.Size, System.Drawing, Version=2.0.0.0, Culture=neutralPublicKeyToken=b03f5f7f11d50a3a</Type>  
  6.       <Value>16, 16</Value>  
  7.     </DefaultValue>  
  8.   </Property>  
  9. </Class>  
这里ImageButton为控件的类名

 

posted @ 2010-06-07 10:59  孖仔爸爸  阅读(364)  评论(0)    收藏  举报