[英]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.