[英]Determine design-time context of a custom winforms control
您可以检查控件是否位于设计器的根目录中。
您可以获取IDesignerHost
服务,然后检查RootComponent
属性,以查看您的控件是否是当前设计器的根组件。
using System.Windows.Forms;
using System.ComponentModel.Design;
public partial class MyBaseControl : UserControl
{
public MyBaseControl()
{
InitializeComponent();
}
public bool IsRootDesigner
{
get
{
var host = (IDesignerHost)this.GetService(typeof(IDesignerHost));
if (host != null)
return host.RootComponent == this;
return false;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.