该方式是直接对屏幕进行截图操作
UserControl chartContainPanel = new UserControl(); Graphics graph = chartContainPanel.CreateGraphics(); Size s = chartContainPanel.Size; Bitmap memoryImage = new Bitmap(s.Width, s.Height, graph); Graphics memoryGraphics = Graphics.FromImage(memoryImage); Point screen = chartContainPanel.PointToScreen(this.Location);
// 拷贝屏幕对应区域为 memoryGraphics 的 BitMap memoryGraphics.CopyFromScreen(screen.X, screen.Y, 0, 0, s); memoryImage.Save(fileName);