我希望有一种方法可以将FlowLayoutPanel的图形内容导出到文件中(不管是什么格式,bmp可能是最简单的)。我也想让它滚动内容,以便导出的文件包含面板的全部内容。
有没有办法做到这一点?我使用的是C# WinForms和Framework4。
发布于 2013-03-25 19:57:49
试着调查一下xml serialization
您可以序列化面板并保存xml。并加载xml并将其反序列化回面板中
也可以查看this。
要保存为图像,只需执行以下操作:
Bitmap image = new Bitmap(flowLayoutPanel1.Width, flowLayoutPanel1.Height);
flowLayoutPanel1.DrawToBitmap(image, new Rectangle(0, 0, flowLayoutPanel1.Width, flowLayoutPanel1.Height));
image.Save("SAVE PATH");发布于 2018-10-17 15:56:24
诀窍是将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 Subhttps://stackoverflow.com/questions/15612706
复制相似问题