I made a program with Windows forms in visual studio c # 2017, and I want to be able to add that the forms automatically adjust to the resolution of the screen, but I have not achieved it. In my search I found the following code:
void AjustarResolución(Form form)
{
String ancho = Screen.PrimaryScreen.Bounds.Size.Width.ToString();//Obtenemos el ancho de la pantalla
String alto = Screen.PrimaryScreen.Bounds.Size.Height.ToString();//Obtenemos el alto de la pantalla
String tamaño = ancho + "x" + alto;//concatenamos para hacer un switch
switch (tamaño)
{
case "800x600":
cambiarResolucion(form, 110F, 110F);//Hacemos el ajuste con esta función
break;
case "1024x600":
cambiarResolucion(form, 96F, 110F);
break;
default:
cambiarResolucion(form, 96F, 110F);
break;
}
}
private static void cambiarResolucion(Form formu, float ancho, float alto)
{
formu.AutoScaleDimensions = new System.Drawing.SizeF(ancho, alto);//Ajustamos la resolución
formu.PerformAutoScale();//Escalo el control y los controles
}
But I have not managed to make it work, it is necessary to clarify that the forms remove the title bar to be able to make a personalized bar. And if you could help me to put this code in a class, so that all the forms can be referenced to that class and not repeating this code with all the forms.