views:

748

answers:

1

I'm creating a collapsible panel control in C# and would like the expand/collapse button to function during design-time as well as run-time. I've gotten this to work fairly well, except that when the control resizes from clicking the button, the resize handles in the designer don't move. When you click on something else and then click back to the collapsible panel they then adjust to the new size. Is there any way to force an update of the entire control in the designer (or perhaps the designer as a whole)? I've tried refreshing and invalidating but neither work.

To get the panel to collapse I have overridden then WndProc method in its Designer as follows:

public class CollapsiblePanelDesigner : ParentControlDesigner
{
    private const int WM_LBUTTONUP = 0x0202;

    protected override void WndProc(ref System.Windows.Forms.Message m)
    {

        if(m.Msg == WM_LBUTTONUP)
        {
            Point p = new Point(m.LParam.ToInt32());

            CollapsiblePanel control = ((CollapsiblePanel)this.Control);
            Label collapseLabel = control.CollapseLabel;

            // Check if the user clicked inside the +/- button
            if (
                p.X >= collapseLabel.Location.X &&
                p.Y >= collapseLabel.Location.Y &&
                p.X < collapseLabel.Location.X + collapseLabel.Width &&
                p.Y < collapseLabel.Location.Y + collapseLabel.Height
            )
            {
                // Resize the control (this method just sets the height to 25)
                control.ResizePanel();
            }
        }

        base.WndProc(ref m);
    }
}

}

Thanks in advance for any help!

A: 

If you're talking about the designer in VS, I don't think it is possible to make controls change their appearence during designing.

Phoexo
It is, and the code I have works fine except for VS not redrawing the resize handles when the size changes.I also have a property for the collapsed state of the panel and that updates fine in designer when changed, just for some reason calling the same exact method from WndProc doesn't.
jlorich