locked
how to create a scrollable picturebox RRS feed

  • Question

  • If it is a small picture(whose size is equal to the picture box size) scrollbar should not appear..if it is not so..it should have scroll bar..once we scroll we can see the remaining part of the image.

    Anyone can provide a code for this. and also usefull link .

     

    thanks and regards,

    Uvaraj T

    Friday, June 30, 2006 5:45 AM

Answers

  • You can find a control (with source code) here:  http://www.codeproject.com/cs/miscctrl/PictureBox.asp
    Friday, June 30, 2006 6:10 AM
  • Rather than using picture box make your own control deriving from a usercontrol.Set the autoscroll prperty to true;

    please see the follwoing code.

    public partial class UserControl1 : UserControl

    {

    private Image image = null;

    public UserControl1()

    {

    InitializeComponent();

    this.AutoScroll = true;

    image = Bitmap.FromFile("C:\\Picture.jpg");//name of the picture to be loaded

    this.AutoScrollMinSize = new Size(image.Width,image.Height);

    }

    protected override void OnPaint(PaintEventArgs e)

    {

    base.OnPaint(e);

    e.Graphics.DrawImage(image, new RectangleF(this.AutoScrollPosition.X ,this.AutoScrollPosition.Y , image.Width, image.Height));

    }

    }

    Friday, June 30, 2006 6:36 AM

All replies

  • You can find a control (with source code) here:  http://www.codeproject.com/cs/miscctrl/PictureBox.asp
    Friday, June 30, 2006 6:10 AM
  • Rather than using picture box make your own control deriving from a usercontrol.Set the autoscroll prperty to true;

    please see the follwoing code.

    public partial class UserControl1 : UserControl

    {

    private Image image = null;

    public UserControl1()

    {

    InitializeComponent();

    this.AutoScroll = true;

    image = Bitmap.FromFile("C:\\Picture.jpg");//name of the picture to be loaded

    this.AutoScrollMinSize = new Size(image.Width,image.Height);

    }

    protected override void OnPaint(PaintEventArgs e)

    {

    base.OnPaint(e);

    e.Graphics.DrawImage(image, new RectangleF(this.AutoScrollPosition.X ,this.AutoScrollPosition.Y , image.Width, image.Height));

    }

    }

    Friday, June 30, 2006 6:36 AM
  • hi mani,
    your thing is working.
    But i ahve a problem like , if i move the scroll bar fast the image is flickering.
    Tuesday, July 4, 2006 5:02 AM
  • Please add the following code in your constructor.It will optimise your paiting.

    this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);

    Tuesday, July 4, 2006 8:41 AM