Here's one way you could approach this: create an EventHandler for the PictureBox SizeChanged Event:
private void pictureBox1_SizeChanged(object sender, EventArgs e)
{
if (pictureBox1.Width == pictureBox1.Height) return;
if (pictureBox1.Width > pictureBox1.Height)
{
pictureBox1.Height = pictureBox1.Width;
}
else
{
pictureBox1.Width = pictureBox1.Height;
}
}
The code shown here will adjust
either the Width or Height of the PictureBox to be equal to the larger dimension.
If your PictureBox is anchored in a way that
only the Width can change, then you can simplify the above code by only testing for Width > Height, and adjusting the Height.
You could also constrain the PictureBox size by setting its MinimumSize and MaximumSize properties. Or, you could, in the SizeChanged EventHandler, constrain the size.
You also should consider the possible effect of the PictureBox's Location when it's resized: depending on the Location and the scaling done, the PictureBox could become partially outside your Form, or other ContainerControl's, bounds.
Note that when you launch a WinForms program, the SizeChanged EventHandler is going to be called twice by the program starting up (tell Microsoft if you don't like this). Often I set a boolean flag in a Form Load EventHandler, and then, in Controls like the PictureBox I test for that boolean flag and exit the EventHandler if it's true. I usually reset that boolean flag to false at the end of the Form Load EventHandler, less often in the Form Shown EventHandler.