• 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;
            tscMain.ContentPanel.Controls.Add(pnlMain);

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

            pboxMain.SizeMode = PictureBoxSizeMode.AutoSize;
            pnlMain.Controls.Add(pboxMain);

            ToolStripButton tsbtn1=new ToolStripButton("push me",null,loadImage);
            tsTop.Items.Add(tsbtn1);

           
            tscMain.TopToolStripPanel.Controls.Add(tsTop);
            tscMain.BottomToolStripPanel.Controls.Add(tsBottom);
            base.Controls.Add(tscMain);

        }

        private void InitializeComponent()
        {
            base.SuspendLayout();
            base.Width = 500;
            base.Height = 500;
            base.CenterToScreen();
            this.ResumeLayout(false);
        }

        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;
            GFX.DrawEllipse(objPen,0,0,1000,1000);
            objBMP.Save(ms,ImageFormat.Bmp);
            pboxMain.Image = Image.FromStream(ms);
        }

 
    }
}
0
mccainz2
Asked:
mccainz2
  • 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.
0
 
dkloeckCommented:
There is a property called ScrollBars, set it to both
0
 
mccainz2Author Commented:
not seeing any property such as ScrollBars on my Panel. Clarify please.
0
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.

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

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