I have a SplitContainer I want to catch the Panel2 collapsing and expanding events.
Any idea how to do that?
Posting this for others that might be hunting for the same answer as I was.
Unfortunately SplitContainer doesn't offer any direct events for the collapsed events. What I have found useful is to monitor the SizeChanged and/or ClientSizeChanged events of the OPPOSITE panel to the one you're collapsing.
Meaning, if I am interested in monitoring collapses of Panel2, I would subscribe to ClientSizeChanged events for Panel1.
In practice I would recommend monitoring the ClientSizeChanged for both panels of the SplitContainer to guarantee you don't miss any initialization or direct splitter movements.
In the below example I have a toggle button (btnToggle) that I want the Checked state to follow the visibility of Panel2 in the SplitContainer:
private void splitContainer_Panel2_ClientSizeChanged(object sender, EventArgs e)
{
btnToggle.Checked = !splitContainer.Panel2Collapsed;
}
private void splitContainer_Panel1_ClientSizeChanged(object sender, EventArgs e)
{
btnToggle.Checked = !splitContainer.Panel2Collapsed;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With