2014-03-06 77 views
1

我想创建一个包含25px页眉的控件。当我添加子控件时,我希望它们的行为像在GroupBox中使用一样。 当控件的DockStyle设置为填入组框时,它的位置自动设置为3;16,它的大小为Width-6; Height-19。 我不想使用填充或边距,因为它们似乎不适用于GroupBox。创建一个包含填充的ContainerControl

我该如何在自己的控件中实现相同的行为?

回答

1

尝试重写面板的DisplayRectangle属性:

public class MyContainer : Panel { 

    public override Rectangle DisplayRectangle { 
    get { 
     int headerHeight = 25; 
     return new Rectangle(
     this.Padding.Left, 
     this.Padding.Top + headerHeight, 
     this.ClientSize.Width - 
      (this.Padding.Left + this.Padding.Right), 
     this.ClientSize.Height - 
      (this.Padding.Top + this.Padding.Bottom + headerHeight)); 
    } 
    } 
} 
+0

谢谢您的回答,我们虽然我发现我自己了。很棒! – dwonisch