您可以创建一个自定义并添加一个属性,如DefaultHeight
,您可以填充当前高度。
事情是这样的:
public class CustomPanel : Panel
{
public int DefaultHeight { get; private set; }
public CustomPanel()
{
// Add an event, which gets triggered at the next resize.
// We need this event, because at initializing the Control have the default Height.
// The Resize event getting triggered, when the Form load and initializes the Controls.
this.Resize += this.Initial_Resize;
}
private void Initial_Resize(object sender, EventArgs e)
{
// Set the DefaultHeight to the value of the new Size
this.DefaultHeight = this.Height;
// Remove the event, otherwise DefaultHeight would get overridden at every resize.
this.Resize -= this.Initial_Resize;
}
}
有了这个代码,你可以使用新的CustomPanel在形式和DefaultHeight
属性崩溃后扩大控制。
可能有更好的方法,但这会帮你没有进一步的努力。任何建议都是值得欢迎的。
请把至今 – Nick
嗨尼克代码添加 – ishtarsg
您可以使用标签的标签属性,你已经尝试过的情况,并设置代码示例到form_load的初始高度。另一种方法是创建从Panel继承的新控件并拥有新属性InitialHeight。使用该控件并在form_load中设置该属性值并使用它来增加面板高度。 –