Detecting when SplitContainer crashed changes

I have a SplitContainer. I want to catch the failure and popup events of Panel2.

Any idea how to do this?

+4
source share
4 answers

Conducting this for others who might be looking for the same answer as me.

Unfortunately, SplitContainer does not offer direct events for collapsed events. What I found useful is to track the SizeChanged and / or ClientSizeChanged events of the OPPOSITE panel with the one you are resetting.

Meaning, if I am interested in observing Panel2 crashes, I would subscribe to ClientSizeChanged events for Panel1.

In practice, I would recommend monitoring ClientSizeChanged for both SplitContainer panels to ensure that you don't miss any initializations or direct separator movements.

In the example below, I have a toggle button (btnToggle) that I want the Checked state to match the Panel2 visibility in 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; } 
+6
source

There is no event for this, but this is because you need to know when it will be minimized when you run the code:

 splitContainer1.Panel1Collapsed = true; // do your stuff 

Otherwise, you can watch the SplitterMoved or SplitterMoving events in the SplitContainer control.

+1
source
 splitContainer.Panel1.VisibleChanged += (s, e) => { bool isPanel1Collapsed = splitContainer.Panel1Collapsed; }; 
+1
source

In the internal implementation, when the panel in the SplitContainer minimized, the Visible property is set to false and vice versa. Thus, you can detect changes when the panel is compressed, handling the VisibleChanged event on the desired panel.

The conclusion is that the SplitterPanel class does not expose this event. However, since it inherits the Panel class that provides this event, you can use it for the Panel and handle the event from there, as shown in the code example below.

 private void Initialize() { split = new SplitContainer(); ((Panel)split.Panel1).VisibleChanged += splitPanel1_Collapsed; } private void splitPanel1_Collapsed(object sender, EventArgs e) { var panel = (SplitterPanel)sender; var panelCollapsed = !panel.Visible; } 
0
source

Source: https://habr.com/ru/post/890720/


All Articles