我在运行时复制一个需要屏幕当前位置的图片框有问题
在这行代码中占据了图片框的位置,但我需要相对于屏幕的位置。我们有办法吗?
// gfxScreenshot.CopyFromScreen(pictureBox1.Bounds.X, pictureBox1.Bounds.Y, 0, 0, pictureBox1.Bounds.Size, CopyPixelOperation.SourceCopy);
if (saveScreenshot.ShowDialog() == DialogResult.OK)
{
bmpScreenshot = new Bitmap(pictureBox1.Bounds.Width, pictureBox1.Bounds.Height, PixelFormat.Format32bppArgb);
gfxScreenshot = Graphics.FromImage(bmpScreenshot);
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
bmpScreenshot.Save(saveScreenshot.FileName, ImageFormat.Png);
}
答案 0 :(得分:3)
要获取图片框本身位置的屏幕坐标,请使用:
var screenPosition = form.PointToScreen(pictureBox1.Location);
获取图片框中某点的屏幕坐标:
var screenPosition = pictureBox1.PointToScreen(new Point(10, 10));
这将为您提供图片框中位置(10,10)的屏幕坐标。