A scrollable PictureBox in C#
Hello, I am learning C# programming and currently creating a program for the A scrollable PictureBox, but I am not able to achieve it. If you are having any solution to achieve it then please provide me code related to it. I have tried it, but I am not able to achieve it. If you are having knowledge about it, then please give me code or details of it.
Re: A scrollable PictureBox in C#
Hello, if you want to create a scrollable Picturebox then the code below will provide you the scrollable picturebox. So, just make use of it.
Code:
public partial class testing : UserControl
{
private Image img = null;
public testing()
{
InitializeComponent();
this.AutoScroll = true;
img = Bitmap.FromFile("C:\\img.jpg");
this.AutoScrollMinSize = new Size(img.Width,img.Height);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawImage(img, new RectangleF(this.AutoScrollPosition.X ,this.AutoScrollPosition.Y , img.Width, img.Height));
}
}
Re: A scrollable PictureBox in C#
Hi, for achieving the scrollable Picturebox in c# you need to make use of the methods below:
- PictureBoxSizeMode.Normal
- PictureBoxSizeMode.CenterImage
- PictureBoxSizeMode.StretchImage
- PictureBoxSizeMode.AutoSize
Re: A scrollable PictureBox in C#
Hello, I have got the code below for making the scrollable PictureBox in C#. You can able to make use of it as per your use.
Code:
private void UserPictureBox_Paint(object provider, System.Windows.Forms.PaintEventArgs e)
{
Graphics gr = e.Graphics;
gr.FillRectangle(Brushes.White,this.CRect);
if (img != null)
{
gr.DrawImageUnscaled(img, -OffsetX, -OffsetY, img.Width, img.Height);
gr.FillRectangle(Brushes.Blue, CRect.Width - vscroll.Width, CRect.Height - hscroll.Height, vscroll.Width, hscroll.Height);
}
}
Re: A scrollable PictureBox in C#
Hello, Creation of such scrollable Picturebox in C# is too much simple. You need to make use of the code below first:
Code:
this.panel1.AutoScroll = true;
Now you need to add the PictureBox control in that panel and then by simply setting the SizeMode to AutoSize and by adding the code below you will able to get the what you want.
Code:
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
Re: A scrollable PictureBox in C#
Hello, you can achieve it Using the control. It is came in the namespace PictureBoxCtrl. Overthere you will get the public class having name as PictureBox : System.Windows.Forms.UserControl. If you make use iof this control then you will able to get the following properties: