0

我想要一种将 FlowLayoutPanel 的图形内容导出到文件的方法(不要介意什么格式,bmp 可能是最简单的)。我还希望它滚动内容,以便导出的文件包含面板的全部内容。

有没有办法做到这一点?我正在使用 C# WinForms 和 Framework 4。

4

2 回答 2

1

尝试查看xml 序列化

您可以序列化面板并保存 xml。并加载xml并将其反序列化回面板

也检查一下

要保存为图像,您只需执行以下操作:

Bitmap image = new Bitmap(flowLayoutPanel1.Width, flowLayoutPanel1.Height);
flowLayoutPanel1.DrawToBitmap(image, new Rectangle(0, 0, flowLayoutPanel1.Width, flowLayoutPanel1.Height));
image.Save("SAVE PATH");
于 2013-03-25T11:57:48.887 回答
0

诀窍是临时将 flowLayoutPanel 设置为适合其中的所有控件,即使它对于可见屏幕来说太大了,然后使用 flowLayoutPanel.clientRectangle 区域而不是 .Width 和 .Height 执行 DrawToBitmap。

在我的示例中,Outside_Splitter 停靠在表单上,​​有两个面板,fraAction 是一个组框,是面板上的最后一个控件,可以垂直滚动。

Public Sub Print_Panel()


    Dim newHeight As Integer
    Dim pos As Point, oheight As Integer, owidth As Integer, xDock As DockStyle
    With Outside_Splitter ' This contains the two panel ...
        pos.X = .Left ' Store original position and size
        pos.Y = .Top
        oheight = .Height
        owidth = .Width
        xDock = .Dock ' get original dock set
        newHeight = FraAction.Top + FraAction.Height + 30 ' calculate new height based on position and size of the last control
        .Dock = DockStyle.None ' undock it
        .Height = newHeight ' set new height 
        .Refresh()
        .SetBounds(pos.X, pos.Y, owidth, newHeight) ' Set position and size, temporarily
        .Refresh()
    End With

    'Create Bitmap based on panel.ClientRectangle   
    Dim myBmp As New Bitmap(Painel_Detalhe_NC.ClientRectangle.Width, Painel_Detalhe_NC.ClientRectangle.Height) 

    'Paint the bitmap
    Painel_Detalhe_NC.DrawToBitmap(myBmp, Painel_Detalhe_NC.ClientRectangle) 

    'Create pdf
    Dim _pdf As New C1.C1Pdf.C1PdfDocument

    _pdf.Clear()
    _pdf.Landscape = False
    _pdf.PaperKind = PaperKind.A4


    Dim rec As New RectangleF ' Set 5% margin around the page 
    rec = _pdf.PageRectangle
    rec.X = 0.05 * rec.Width
    rec.Y = 0.05 * rec.Height
    rec.Width = 0.9 * _pdf.PageRectangle.Width
    rec.Height = 0.9 * _pdf.PageRectangle.Height


    _pdf.DrawImage(myBmp, rec) ' paint/resize bitmap to that size on the pdf

    'Save it and show it 
    _pdf.Save(My.Computer.FileSystem.SpecialDirectories.Temp & "\temp.pdf")
    Process.Start(My.Computer.FileSystem.SpecialDirectories.Temp & "\temp.pdf")

    myBmp.Dispose() ' Clear it

    With Outside_Splitter ' put it back to where it was
        .Left = pos.X
        .Top = pos.Y
        .Dock = xDock ' Back to filling the form
        .Refresh()

    End With
    End  Sub
于 2018-10-17T07:56:23.740 回答