Was taking a look at a screen rotation (portrait to landscape and back) issue we were having in one of our soon to be released products when using the TabControl/TabPage.Height property and Compact Framework 2.0 and Windows Mobile 5.0.
When the screen orientation changed, the Form.Resize event is raised. Great, easy enough to adjust some ListViews that are in the TabPage using the following code:
listView2.Height = listView1.Height = (tabControl1.TabPages.Height / 2) – 2;
Although you think it would work, it doesn’t because the TabPages.Height property is the Height before the Screen rotation occurs.
To work around this is easy enough, just use the Form.Height properties.
listView1.Height = listView2.Height = (this.Height – (20 * m_scale)) / 2;
- 20 is the height of the tabs
- m_scale is to support hi res devices
Download the sample code here.
UPDATE: Got a comment here about using docking and anchoring which is true but for some reason was not working properly in our application, don’t know why so we resorted to manually calculating sizes. I updated the sample code which shows the ListViews properly sizing using the Anchor property on rotation.