Don’t forget to call your base

I’m working on a windows forms app in my spare time, and I just ran into this very frustrating issue.

I have a SplitContainer on the main form to divide my form.  I wanted the SplitContainer to resize with the form so that when you resize the form, the form elements would also stretch and shrink.  I had set the SplitContainer’s Dock to DockStyle.Fill (which is all I usually have to do) but the damn thing just would NOT resize.  I had also set one of the panels in the SplitContainer to be fixed, so I thought that may be causing the issue, I also read on msdn that the docking respects the z-order of the controls and since I had added the SplitContainer after the other controls, I figured that may have something to do with it as well.

I easily created a new blank form with a SplitContainer and set that one to fill (even with a fixed panel) and it worked like a charm, argh!  To open this test form I just added some code to my main form’s OnLoad method to show my blank test form.  Right below my OnLoad method was the OnResize method.  When I minimize my app, I want it to show up in the system tray, but not the taskbar, so here was my code for OnResize:

protected override void OnResize(EventArgs e)

{

if (WindowState == FormWindowState.Minimized)

Hide();

}

I realized I wasn’t calling base.OnResize(e).  I added that line, voila! My docking now worked as expected :)

Leave a Comment

Name: (Required)

E-mail: (Required)

Website:

Enter my name (ben) in this box, so I know you're a human.

Comment: