Cómo cambiar el tamaño y ajustar automáticamente los controles de formulario con el cambio de resolución


He notado que algunas aplicaciones cambian su posición de controles para ajustarlos tanto como sea posible en la resolución como sea posible, Si la ventana se maximiza se establecen de tal manera que sobre toda la GUI se ve equilibrada. Mi pregunta es si es posible hacer o implementar esta funcionalidad en Visual studio 2010 C#?

Author: Afnan Bashir, 2010-11-22

8 answers

Use Docky Anchor propiedades. Aquí es un buen artículo. Tenga en cuenta que estos manejarán los cambios al maximizar/minimizar. Eso es un poco diferente que si la resolución de la pantalla cambia, pero será a lo largo de la misma idea.

 60
Author: SwDevMan81,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-11-12 11:27:29

Use combinaciones de estos para obtener el resultado deseado:

  1. Establezca la propiedad Anchor en None, los controles no se redimensionarán, solo cambiarán su posición.

  2. Establezca la propiedad Anchor en Top+Bottom+Left+Right, los controles se redimensionarán pero no cambiarán su posición.

  3. Establezca el Minimum Size del formulario en un valor apropiado.

  4. Establecer la propiedad Dock.

  5. Use el evento Form Resize para cambiar lo que sea que want

No se como tamaño de fuente (etiqueta, cuadro de texto, combobox, etc.) se verá afectado en (1) - (4), pero se puede controlar en (5).

 16
Author: Bhaskar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-25 10:40:12
float widthRatio = Screen.PrimaryScreen.Bounds.Width / 1280;
float heightRatio = Screen.PrimaryScreen.Bounds.Height / 800f;
SizeF scale = new SizeF(widthRatio, heightRatio);
this.Scale(scale);
foreach (Control control in this.Controls)
{
control.Font = new Font("Verdana", control.Font.SizeInPoints * heightRatio * widthRatio);
}
 9
Author: Mohammad Shahnawaz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-09-16 07:15:07

..y para detectar un cambio en la resolución para manejarlo (una vez que esté utilizando el acoplamiento y el anclaje como sugiere SwDevMan81) use el SystemEvents.DisplaySettingsChanged event en Microsoft.Win32 .

 2
Author: Thushan Fernando,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-11-23 07:45:12

En el evento de carga del formulario agregue esta línea

this.WindowState = FormWindowState.Maximized;
 0
Author: soldiershin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-06-14 09:45:56

Agregue este código al cargar la página do para todos los controles o agregue todos los controles en contenedores

int x;
Point pt = new Point();
x = Screen.PrimaryScreen.WorkingArea.Width - 1024;
x = x / 2;
pt.Y = groupBox1.Location.Y + 50;
pt.X = groupBox1.Location.X + x;
groupBox1.Location = pt;
 -1
Author: chirag,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-02-04 13:08:05
private void MainForm_Load( object sender, EventArgs e ) 
     { 
        this.Size = Screen.PrimaryScreen.WorkingArea.Size 
     }
 -1
Author: Sherif Hamdy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-02-26 02:08:54
this.WindowState = FormWindowState.Maximized;
 -2
Author: user6899728,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-09-29 13:15:00