Some controls not resizing

  • Thread starter Thread starter tendaimare
  • Start date Start date
T

tendaimare

Guest
I have code thats resizing my controls in line with the screen size / resolution. My development monitor has a resolution of 1920 * 1080 and if I compile the program and run on a machine with a lower resolution the controls should resize in line with the screen settings. Some of the forms where I run this code are perfectly running well but on some forms this code is not working as expected

This is the code that I am using :

#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

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);


This code is perfectly working on a lot of my forms but I am struggling to figure out why its not working on other forms as well



If you think it you can achieve it

Continue reading...
 
Back
Top