Scrollbars not working correctly on my picturebox

Posted on 2006-06-07
Last Modified: 2007-12-19
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);

Question by:mccainz2
    LVL 5

    Author Comment

    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.
    LVL 10

    Expert Comment

    There is a property called ScrollBars, set it to both
    LVL 5

    Author Comment

    not seeing any property such as ScrollBars on my Panel. Clarify please.
    LVL 10

    Expert Comment

    LVL 96

    Accepted Solution

    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.

    LVL 5

    Author Comment

    Thanks Bob, will modify the code and respond back...

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    How to count json data 2 43
    Good resource for accessibility implementation 1 30
    Handling arrays 14 28
    What is MicroStrategy.NET? 2 29
    Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
    Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now