我尝试使用ScrollBars在Windows Forms C#中开发一个应用程序,遇到了一个问题,无论你如何输入
rect.X = (int)(pictureBox1.HorizontalScroll.Value / zoomLevel); rect.Y = (int)(pictureBox1.VerticalScroll.Value / zoomLevel);
它都不起作用,我尝试替换VerticalScroll.Value to vScrollBar1.Value
但它仍然不起作用。还连接了支持滚动条的using System.Windows.Forms;
。预先感谢您的回答和帮助。
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);`