Link to home
Start Free TrialLog in
Avatar of mccainz2
mccainz2

asked on

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);
        }

 
    }
}
Avatar of mccainz2
mccainz2

ASKER

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
not seeing any property such as ScrollBars on my Panel. Clarify please.
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Bob, will modify the code and respond back...