前一段時間我已經實現,其中我創建的自定義鹼的形式和控制實現的溶液,加入一個屬性並覆蓋在onLoad方法:
public partial class FormBase : Form
{
public FormBase()
{
this.InitializeComponent();
}
protected ConsistencyManager ConsistencyManager { get; private set; }
protected override void OnLoad(System.EventArgs e)
{
base.OnLoad(e);
if (this.ConsistencyManager == null)
{
this.ConsistencyManager = new ConsistencyManager(this);
this.ConsistencyManager.MakeConsistent();
}
}
}
的ConsistencyManager類查找所有控件,組件也支持在特定控件中搜索自定義子控件。從MakeConsistent方法複製/粘貼代碼:
public void MakeConsistent()
{
if (this.components == null)
{
List<IComponent> additionalComponents = new List<IComponent>();
// get all controls, including the current one
this.components =
this.GetAllControls(this.parentControl)
.Concat(GetAllComponents(this.parentControl))
.Concat(new Control[] { this.parentControl });
// now find additional components, which are not present neither in Controls collection nor in components
foreach (var component in this.components)
{
IAdditionalComponentsProvider provider = GetAdditinalComponentsProvider(component.GetType().FullName);
if (provider != null)
{
additionalComponents.AddRange(provider.GetChildComponents(component));
}
}
if (additionalComponents.Count > 0)
{
this.components = this.components.Concat(additionalComponents);
}
}
this.MakeConsistent(this.components);
}
如果有人想要完整的示例或源代碼請告訴我。
最好的問候, Zvonko
PS:以同樣的方式我也創建了統計上的主線程調用數性能計數器。
WinForms,我收集? – HackedByChinese
一切,其實。 我的例子確實來自WinForms。在WPF中,實現起來更容易一些。 – Zvonko
WebForms,MVC和WPF是一種不同的動物,因爲它們利用樣式表,這意味着除非這些變化對佈局有很大影響(定位,大小等方面的巨大變化),否則這些變化很微不足道。這是WinForms的另一個問題。 – HackedByChinese