Developing Windows Forms collaboratively using machines with varying screen resolutions can lead to inadvertent (and automatic) changes to form layout, size and display being checked into source control. This leads to wasted development time and frustrated developers.
Developing Windows Forms projects can be a time consuming affair. Designing the layout alone can be an involved process and a large time investment in order to get the desired look and feel of an application’s UI. Making sure the UI looks correct on different devices and screen sizes would be a burdensome task if it weren’t for a feature of Windows Forms known as Automatic Scaling. Automatic Scaling is a mechanism that Windows Forms use by default to resize forms, controls, etc. at runtime so that when displayed on different screens with different resolutions, the design of the form as assembled on the development machine remains intact. While this is a desired feature (and although configurable, should never be turned off), it can cause problems when multiple developers are working on the same set of forms and controls using machines with differing screen resolutions.
The problem stems from the fact that, although Automatic Scaling will appropriately resize Windows Forms components at runtime, the forms designer - and associated automatically generated code - will recalculate and adjust existing size and position pixel values for both the form itself and all control elements if any changes are made to the corresponding forms on a machine with different resolution than the previous development machine. In turn, these newly generated values will often distort and mangle the layout of the UI going forward. If a developer isn’t paying attention to this phenomenon when doing UI work, they may check in the undesired changes to source control and introduce a host of problems to the UI that will need to be unwound.
In order to ameliorate this problem, any developers on the team that will be contributing to the Windows Forms project will need to adjust the screen resolution of their machine to match that of the machine that the forms were initially created on. This is accomplished by adjusting the scaling factor of the development machine’s display.
To make this adjustment:
- Open the Control Panel and select Appearance and Personalization
- Find the Display header and select Make Text And Other Items Larger Or Smaller
- Open the Control Panel and select Display
- Check the ‘Let me choose one scaling level for all my displays’ box
- Click on the Windows Start Menu and open Settings
- Select System
When adjusting the scaling factor on the development machine, this will oftentimes mean setting the scaling factor to 100% (down from the recommended 125%). The user will then need to sign out of their current Windows session and sign back in before the new scaling factor setting will be incorporated by Visual Studio. Once the resolution settings have been corrected, subsequent changes to the forms and controls in the Windows Forms project will not trigger the Automatic Scaling mechanism in Visual Studio.
Collaborative development on Windows Forms projects can be a tricky proposition thanks to the side effects of Automatic Scaling. Ensure that your team is aware of the display settings of the machine used to initially develop the project’s UI so that they may take the steps necessary to implement consistent environment configuration and prevent a headache or three.