I am extending the PictureBox example in a Microsoft tutorial on Visual Studio. I have a hierarchy of: Form - TableLayoutPanel - Panel - PictureBox; the tableLayoutPanel is set for a 2x2 grid; the Panel is set to span the first two columns so it occupies the top of the form, and there is a checkbox in the lower left cell of the tableLayoutPanel grid and some buttons in its lower right.
I have one of the buttons working to select an image and display it in the picture box. I want checking the checkbox to fit the image into the picture box at the largest size allowed by the space, an unchecking the checkbox to display whatever part of the full-size image will fit in the picture box, with scrollbars to move that view around.
When I check the checkbox, the fitted picture appears as I want it to. When I uncheck the checkbox, it displays that portion of the image that will fit in the space, but it does not display the scrollbars. How do I switch back and forth so that I get scroll bars when the image is bigger than the picture box, and not when the image is fitted in the space, all within these first two cells of a TableLayoutPanel?
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked) // gives state after the change
{
picMainPicture.SizeMode = PictureBoxSizeMode.Zoom;
}
else
{
picMainPicture.SizeMode = PictureBoxSizeMode.AutoSize;
}
}
Properties that I think matter for the panel at start:
Anchor: Top, Left
AutoScroll: True
Dock: Fill
ColumnSpan: 2
Location: 4,4
Size: 993, 501 // would happily reduce this if I knew how, it won't let me enter new numbers
Properties that I think matter for the pictureBox:
Anchor: Top, Left
Dock: Fill
Location: 0,0
Size: 993, 501
SizeMode: AutoSize