1
votes

I have a Windows Forms application that contains a TabControl that I am using to display an image for each TabPage.

Inside the TabPage I place a CustomControl for displaying the image. The CustomControl has some checkboxes for setting the image layout, PictureBox, and a Button to remove the image. This is what my Custom Control looks like:

Image Preview Custom Control

I want the PictureBox to be scrollable so in order to do so I add a Panel to the CustomControl:

Image Preview Custom Control - Panel

I set the Anchor property of this Panel to Left|Right|Top|Bottom and the AutoScroll property to True.

Next, I place the PictureBox inside the Panel I set its Anchor property to Left|Right|Top|Bottom and SizeMode to AutoSize:

Image Preview Custom Control - PictureBox

When I start my application and I click an "Add Image" button I programatically add a new TabPage containing my CustomControl then add the image to the CustomControl:

// inside my main forms callback
ImagePreviewCustomControl previewControl = new ImagePreviewCustomControl(bitMap);
previewControl.Dock = DockStyle.Fill;
TabPage tabPage = new TabPage(Path.GetFileNameWithoutExtension(imageFileName));                
tabPage.Controls.Add(previewControl);
imagesTabControl.TabPages.Add(tabPage);

// inside the custom control after the constructor
imagePreviewPictureBox.BackgroundImage = bitMap;
imagePreviewPictureBox.BackgroundImageLayout = imageLayout;

I don't see any scrollbars, however, if the image added is bigger than the PictureBox. (The image dimensions are 1035 x 1024 so it's much bigger than the PictureBox.)

Here is a screenshot:

Tab Control With TabPage Containing Picture

Am I setting the properties of either the Panel or PictureBox incorrectly? If so, what do I need to do?

Thank you.

==UPDATE==================================

I changed the Anchor property of the PictureBox to none as suggested. Here is my updated layout:

Image Preview Custom Control - PictureBox

However this still doesn't work. I am seeing the same issue. No scrollbars

Could this have something to do with the fact that when I add the CustomControl to the TabPage I set it's Dock to Fill?

ImagePreviewCustomControl previewControl = new ImagePreviewCustomControl(bitMap);
previewControl.Dock = DockStyle.Fill; // << << <<
TabPage tabPage = new TabPage(Path.GetFileNameWithoutExtension(imageFileName));                
tabPage.Controls.Add(previewControl);
imagesTabControl.TabPages.Add(tabPage);

==========================================

1

1 Answers

1
votes

Next, I place the PictureBox inside the Panel I set its Anchor property to Left|Right|Top|Bottom ...

And thus the Panel doesn't need to scroll because the picture box never goes outside the view port. Don't Anchor the picture box.