导出部分窗口形式为图像

Jon*_*nah 1 vb.net mschart visual-studio-2008 visual-studio

我有一个表单,显示在Microsoft Chart控件6.0中生成的图表...

我在菜单栏中放置了一个选项,它会将图形导出到图像文件中...

有人可以告诉如何将表单的图形部分导出为图像(任何格式都可以)...

我正在考虑截取屏幕截图并保存它,但我在vb中获取控件以获取表单上指定区域的屏幕截图.

Bal*_*a R 6

这是它的C#功能

private void capture(Control ctrl, string fileName)
{
    Rectangle bounds = ctrl.Bounds;
    Point pt = ctrl.PointToScreen(bounds.Location);
    Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height);
    using (Graphics g = Graphics.FromImage(bitmap))
    {
        g.CopyFromScreen(new Point(pt.X - ctrl.Location.X, pt.Y - ctrl.Location.Y), Point.Empty, bounds.Size);
    }

    bitmap.Save(fileName,ImageFormat.Png);
}
Run Code Online (Sandbox Code Playgroud)

并打电话

capture(chart1, @"c:\temp.png");
Run Code Online (Sandbox Code Playgroud)

这是上面转换为VB的c#方法

Private Sub capture(ctrl As Control, fileName As String)
    Dim bounds As Rectangle = ctrl.Bounds
    Dim pt As Point = ctrl.PointToScreen(bounds.Location)
    Dim bitmap As New Bitmap(bounds.Width, bounds.Height)
    Using g As Graphics = Graphics.FromImage(bitmap)
        g.CopyFromScreen(New Point(pt.X - ctrl.Location.X, pt.Y - ctrl.Location.Y), Point.Empty, bounds.Size)
    End Using

    bitmap.Save(fileName, ImageFormat.Png)
End Sub
Run Code Online (Sandbox Code Playgroud)