Question

I want to create a control that contains a 25px Header. When I add child controls I want them to behave like they would be used in a GroupBox. When a control's DockStyle is set to Fill in a groupbox, it's location is automatically set to 3;16 and it's size to Width-6; Height-19. I do not wan't to use Padding or Margin, as they seem not to be used in GroupBox.

How could I achieve same behavior in my own controls?

Was it helpful?

Solution

Try overriding the DisplayRectangle property of a panel:

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));
    }
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top