• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1201
  • Last Modified:

Scrollbars not working correctly on my picturebox

I have a windows form with the following basic structure....

Picturebox nested on a Panel nested on a ToolStripContainer.ContentPanel.

I've set the picturebox.sizemode to AutoSize and the Panel.autoscroll property to true.
Next I generate a BMP which exceeds the X and Y bounds of the form and place it as the image on the picturebox.
When I do this the vertical scrollbar shows up but the horizontal scrollbar is missing? What am I missing here??

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

namespace Project1
    /* DEMO class for exploring behavior of scrollbars,
     * dockstyles, and anchorstyles.
    class clsGUI : Form
        ToolStripContainer tscMain = new ToolStripContainer();
        ToolStrip tsTop = new ToolStrip();
        ToolStrip tsBottom = new ToolStrip();
        Panel pnlMain = new Panel();
        PictureBox pboxMain = new PictureBox();

        public clsGUI()
            //tool strip container
            tscMain.Anchor = AnchorStyles.Top & AnchorStyles.Left;
            tscMain.Dock = DockStyle.Fill;

            //panel nested on the toolstrip container contentpanel
            pnlMain.Anchor = AnchorStyles.Top & AnchorStyles.Left;
            pnlMain.Dock = DockStyle.Fill;
            pnlMain.AutoScroll = true;
            pnlMain.BackColor = Color.DarkGray;

            //picturebox nested on pnlMain
            pboxMain.Anchor = AnchorStyles.Top & AnchorStyles.Left;
            pboxMain.Dock = DockStyle.Top;

            pboxMain.SizeMode = PictureBoxSizeMode.AutoSize;

            ToolStripButton tsbtn1=new ToolStripButton("push me",null,loadImage);



        private void InitializeComponent()
            base.Width = 500;
            base.Height = 500;

        private void loadImage(object sender, EventArgs e)

            Bitmap objBMP = new Bitmap(1000, 1000);
            MemoryStream ms=new MemoryStream();
            Graphics GFX=Graphics.FromImage(objBMP);
            Pen objPen = new Pen(Color.Red);
            objPen.Width = 10;
            pboxMain.Image = Image.FromStream(ms);

  • 3
  • 2
1 Solution
mccainz2Author Commented:
One thing I have noticed is that if I set my picturebox dockstyle to left I get the horizontal scrollbar but not the vertical and if I set the picturebox dockstyle to top I get the vertical but not the horizontal. Beyond that if I set the dockstyle to Fill I get neither scrollbar.
There is a property called ScrollBars, set it to both
mccainz2Author Commented:
not seeing any property such as ScrollBars on my Panel. Clarify please.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Bob LearnedCommented:
If you are using the AutoSize mode, don't set the Anchors or Docking property.  Let the control spill out beyond the limits of the panel.

mccainz2Author Commented:
Thanks Bob, will modify the code and respond back...

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now