December 15, 2015

Scroll bar disappears on minimizing of window - C# .NET winform


While working on windows based project, I found a strange issue - on minimizing of window to task bar and returning to its normal state by maximizing, some of its controls and scroll bar were disappearing. Those get displayed automatically on changing of window’s state or re-sizing of the form.

I tried lots to find out its solution over internet but I did not found any good solution, what I found is that this is a .NET bug which has been fixed in framework 4.5, whereas I was using .NET framework 3.5, and therefore looking for alternate solution. For detail, you can visit:


While discussing with my senior, I found a hint about to override base class method OnSizeChanged(). After fighting with code lines while RnD and using Visual Studio class editor help, I found the solution what exactly I was looking, and the solution is given below:

protected override void OnSizeChanged(EventArgs e)
if (this.WindowState == FormWindowState.Maximized || 
this.WindowState == FormWindowState.Normal)
       if (this.WindowState == FormWindowState.Minimized)


Understanding the code

Override base class method OnSizeChanged() in your form class to restore form state, on conditional basis. For window’s minimize state, call ResumeLayout() method to resume controls layout as well its data. For window’s maximize and normal state, call base class method OnSizeChanged() to refresh the form controls.


In my case, ‘Dock’ property could not resolve my issue. This solution is not a rocket science but as this issues I have faced was strange and therefore, I wish to share it, someone my take help from this.