-7

I am designing a control (below) called ViewPanel. Essentially it's just a panel that draws it's Text property as a title. To do this, I adjust the DisplayRectangle property to allow enough space at the top to draw some text.

The problem I am experiecing (and have been experiencing for a lot of owner-drawn controls that manipulate DisplayRectangle) is that when the control is resized, it's child controls seem to lag behind a bit.

Example:

Example control

As you can see here, I have a ViewPanel control, which has drawn a blue titlebar, also note that the ViewPanel is padded 16px in every direction!

The ViewPanel control has a single child (ListView)

I have resized the control - notice how the ViewPanel has drawn it's titlebar correctly, but the child has not repositioned itself accordingly.

Question:

What is responsible for updating the location of child controls? Do I need to override something?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Matthew Layton
  • 39,871
  • 52
  • 185
  • 313

1 Answers1

-2

Solved (for anyone else owner-drawing controls):

protected override void WndProc(ref Message m)
{
    const int WM_WINDOWPOSCHANGED = 0x0047;
    base.WndProc(ref m);
    if (m.Msg == WM_WINDOWPOSCHANGED)
    {
        //Make changes to your display rectangle here...
        this.PerformLayout();
    }
}
Matthew Layton
  • 39,871
  • 52
  • 185
  • 313