I have code to resize controls on my forms, so that they can display "responsively" on any screen resolution, this code is working perfectly on some of my forms but unfortunately is not working on my other forms.
I was suspecting that maybe because some of the controls where in Group-boxes and panels, so maybe they where not being "reached", but the code has proved that is is not the answer.
Here is some of the code
#region Scale Controls To Screen Size
Responsive ResponsiveObj;
private void ScaleControls(Control.ControlCollection controls)
{
foreach (Control ctl in controls)
{
Scale(ctl);
if (ctl is GroupBox || ctl is StatusStrip || ctl is DevExpress.XtraEditors.BarCodeControl || ctl is Panel || ctl is LabelControl || ctl is DevExpress.XtraBars.Navigation.TabPane || ctl is DevExpress.XtraBars.Navigation.TabNavigationPage) // Recursive call if it is a Groupbox (which has more controls inside it).
ScaleControls(ctl.Controls);
}
}
private void Scale(Control ctl)
{
ctl.Font = new Font(ctl.Font.Name, ResponsiveObj.GetMetrics((int)ctl.Font.Size), ctl.Font.Style);
if (ctl is LookUpEdit)
{
(ctl as LookUpEdit).Properties.Appearance.Font = ctl.Font;
(ctl as LookUpEdit).Properties.AppearanceDisabled.Font = ctl.Font;
(ctl as LookUpEdit).Properties.AppearanceDropDown.Font = ctl.Font;
(ctl as LookUpEdit).Properties.AppearanceDropDownHeader.Font = ctl.Font;
(ctl as LookUpEdit).Properties.AppearanceFocused.Font = ctl.Font;
(ctl as LookUpEdit).Properties.AppearanceReadOnly.Font = ctl.Font;
}
ctl.Width = ResponsiveObj.GetMetrics(ctl.Width, "Width");
ctl.Height = ResponsiveObj.GetMetrics(ctl.Height, "Height");
ctl.Top = ResponsiveObj.GetMetrics(ctl.Top, "Top");
ctl.Left = ResponsiveObj.GetMetrics(ctl.Left, "Left");
}
#endregion
In the constructor
ResponsiveObj = new Responsive(Screen.PrimaryScreen.Bounds);
ResponsiveObj.SetMultiplicationFactor();
In the Form Load event
Width = ResponsiveObj.GetMetrics(Width, "Width"); // Form width and height set up.
Height = ResponsiveObj.GetMetrics(Height, "Height");
Left = Screen.GetBounds(this).Width / 2 - Width / 2; // Form centering.
Top = Screen.GetBounds(this).Height / 2 - Height / 2 - 30; // 30 is a calibration factor.
ScaleControls(Controls);
I thought maybe the ScaleControls procedure was not accessing all the controls so I changed it but still got the same result
private void ScaleControls(Control.ControlCollection controls)
{
foreach (Control ctl in controls)
{
Scale(ctl);
if (ctl.HasChildren) // Recursive call if it is a Groupbox (which has more controls inside it).
ScaleControls(ctl.Controls);
}
}
I am realizing that some of my controls might not be included in the controls collection like the TextEdit control for example - I am trying to find a way to create a list of all controls including the TextEdit control along with other DevExpress controls so that they can be resized
I just uploaded a sample project on Microsoft Onedrive here. The project was developed on a 1920 * 1080 monitor but we want the forms to adjust and show nicely even on other smaller monitors like 1600 * 900 for example. The first form In Big responds well on other smaller monitor the font sizes are scaled properly and the controls are placed rightly on 1600 * 900 monitors. But the second form Outbound is not resized right . the Full Weight and Empty Weight TextEdit are not resized and the font is not right - and yet that form is a copy of the In Big form with a few adjustments.I would like for the controls and fonts to resize properly even in the Outbound form like its doing in the In Big form
I found out that in the "Big In" form the tabPane DevExpress control was docked but in the other forms it was not . this suttle difference was the one causing the problem