0

I tried to develop an application in Windows Forms C# using ScrollBars, and ran into a problem that no matter how you type in rect.X = (int)(pictureBox1.HorizontalScroll.Value / zoomLevel); rect.Y = (int)(pictureBox1.VerticalScroll.Value / zoomLevel); it does not work, I tried to replace VerticalScroll.Value to vScrollBar1.Value but it still does not work. Also connected using System.Windows.Forms; which has support for ScrollBars. Thank you in advance for your answers and help.

Rectangle rect = new Rectangle();
rect.Width = (int)(pictureBox1.Width / zoomLevel);
rect.Height = (int)(pictureBox1.Height / zoomLevel);
rect.X = (int)(pictureBox1.HorizontalScroll.Value / zoomLevel);
rect.Y = (int)(pictureBox1.VerticalScroll.Value / zoomLevel);

Bitmap bitmap = new Bitmap(rect.Width, rect.Height);
using (Graphics g = Graphics.FromImage(bitmap))
{
g.DrawImage(pictureBox1.Image, new Rectangle(0, 0, rect.Width, rect.Height), rect, GraphicsUnit.Pixel);
}

bitmap.Save(fileName, format);

PropertyItem hScrollItem = pictureBox1.HorizontalScroll.CreatePropertyItem();
hScrollItem.Id = 1;
hScrollItem.Type = 4;
hScrollItem.Value = BitConverter.GetBytes(pictureBox1.HorizontalScroll.Value);

PropertyItem vScrollItem = pictureBox1.VerticalScroll.CreatePropertyItem();
vScrollItem.Id = 2;
vScrollItem.Type = 4;
vScrollItem.Value = BitConverter.GetBytes(pictureBox1.VerticalScroll.Value);`
Son of Man
  • 1,213
  • 2
  • 7
  • 27
XCtony
  • 3
  • 1

0 Answers0