Is there an easy way to set the zoom level for a windows form in C#? In VBA there was a zoom property of the form.
There is no way (that I know of) to do what you ask with typical WinForms.
If you're doing custom painting/drawing, you can zoom that by using a zoom transform, but so far as I know there is no "Zoom" property for the form in the entire world of .NET and native Windows/C++ APIs combined.
You could probably rig something yourself such that you scale controls by a constant factor. And you can probably find 3rd-party controls/surfaces which support this. And who knows what is possible with WPF. But in a typical WinForms world, no.
I had the same problem and I solved it this way in c#. Code goes on Form load
float scaleX = ((float)Screen.PrimaryScreen.WorkingArea.Width / 1024);
float scaleY = ((float)Screen.PrimaryScreen.WorkingArea.Height / 768);
SizeF aSf = new SizeF(scaleX, scaleY);
this.Scale(aSf);
This "more or less" scales form and all children. Loops forever in 800x600 (?) You have to set the following Form properties:
AutoscaleMode = Font
AutoSize = False
You can get some kind of zoom by assigning different Font to the Form, all the controls will be zoomed accordingly if AutoScaleMode set to Font. Also settings AutoSize to False will keep form size intact, the controls will grow to the center of the form. You need to set up all Anchors correctly and test the look, since its just "kind of zoom".
So basically here is sample constructor:
public Form1()
{
InitializeComponent();
AutoSize = false;
AutoScaleMode = AutoScaleMode.Font;
Font = new Font("Trebuchet MS",
10.0f,
FontStyle.Regular,
GraphicsUnit.Point,
((byte)(204))
);
}
After form has been shown assigning new Font will mess up all the controls and this trick will not work.
There is no way (that I know of) to do what you ask with typical WinForms.
If you're doing custom painting/drawing, you can zoom that by using a zoom transform, but so far as I know there is no "Zoom" property for the form in the entire world of .NET and native Windows/C++ APIs combined.
You could probably rig something yourself such that you scale controls by a constant factor. And you can probably find 3rd-party controls/surfaces which support this. And who knows what is possible with WPF. But in a typical WinForms world, no.
This works
private void button1_Click(object sender, EventArgs e)
{
ScaleForm(1.1f); // Scale up by 10%
//ScaleForm(0.9f); // Scale down by 10%
}
private void ScaleForm(float scaleFactor)
{
this.Scale(new SizeF(scaleFactor, scaleFactor));
foreach (Control control in this.Controls)
{
control.Scale(new SizeF(scaleFactor, scaleFactor));
}
}
© 2022 - 2025 — McMap. All rights reserved.