![](/img/trans.png)
[英]Can I change the properties of a HttpClientHandler after the HttpClient has been created?
[英]How could I change the properties of a Control after the resource file has been applied?
當用戶將字體大小更改為125%或150%時,我需要為組件添加滾動條。 為此,我在組件中添加了一個方法,該方法將AutoScroll屬性設置為true。
protected override void OnSizeChanged(EventArgs e)
{
if (SystemFonts.DefaultFont.Size < 8)
{
this.AutoScroll = true;
}
if (this.Handle != null)
{
this.BeginInvoke((MethodInvoker) delegate
{
base.OnSizeChanged(e);
});
}
}
這很好用,但其中一個組件不應該有滾動條。
初始化控制器時會觸發上述方法,如下所示:
this.ultraExpandableGroupBoxPanel1.Controls.Add(this.pnlViewMode);
this.ultraExpandableGroupBoxPanel1.Controls.Add(this.ucASNSearchCriteria);
resources.ApplyResources(this.ultraExpandableGroupBoxPanel1, "ultraExpandableGroupBoxPanel1");
this.ultraExpandableGroupBoxPanel1.Name = "ultraExpandableGroupBoxPanel1";
添加到控件中時將觸發該方法,之后將應用該資源。 我不想更改的組件屬於上面代碼中的ucASNSearchCriteria
。
現在我想在應用資源后將'ucASNSearchCriteria'的AutoScroll
屬性設置為false。 我對c#ui控件的渲染過程知之甚少。 應用后是否可以動態更改屬性?
我將創建一個所需類型的派生控件,並添加一個屬性AllowAutoScroll
或類似的東西,默認值為true
。
有了這個,您可以輕松地在WinForms設計器中更改該屬性,並在大小發生變化時對該屬性做出反應。
因此,如果您將其更改為非默認值( false
),設計人員將為您添加此行代碼:
this.ucASNSearchCriteria.AllowAutoScroll = false;
......你可以像這樣對這個新房產做出反應:
protected override void OnSizeChanged(EventArgs e)
{
if (AllowAutoScroll)
{
if (SystemFonts.DefaultFont.Size < 8)
{
this.AutoScroll = true;
}
if (this.Handle != null)
{
this.BeginInvoke((MethodInvoker) delegate
{
base.OnSizeChanged(e);
});
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.