当前位置:编程学习 > C#/ASP.NET >>

怎么样根据画面上的容器控件,生成相对应的图片?

我现在有个form,form里有一个panle,
panle中控件若干(总数不定,并且可能画面中显示不全panle会出现滚动条),
现在需要把panle中所有的东西按照画面的样子做成一张图片。
求高手给予帮助!!! --------------------编程问答-------------------- 你参考 Me.Panel1.DrawToBitmap --------------------编程问答-------------------- 两个函数:

  Public Sub DrawControl(ByVal _Control As Control, ByVal _Bitmap As Bitmap)
        _Control.DrawToBitmap(_Bitmap, _Control.Bounds)
        For Each childControl As Control In _Control.Controls
            DrawControl(childControl, _Bitmap)
        Next
    End Sub

    Public Sub SaveBitmap(ByVal _Panel As Panel, ByVal fileName As String)
        Using bmp As New Bitmap(_Panel.Width, _Panel.Height)
            _Panel.DrawToBitmap(bmp, New Rectangle(0, 0, _Panel.Width, _Panel.Height))
            For Each _control As Control In _Panel.Controls
                DrawControl(_control, bmp)
            Next
            bmp.Save(fileName)
        End Using
    End Sub

调用方法:

 SaveBitmap(Me.Panel1, "d:\cc.bmp")
--------------------编程问答--------------------
引用 2 楼 linjimu 的回复:
两个函数:

VB.NET code


  Public Sub DrawControl(ByVal _Control As Control, ByVal _Bitmap As Bitmap)
        _Control.DrawToBitmap(_Bitmap, _Control.Bounds)
        For Each childControl As Contro……


+++1 --------------------编程问答--------------------
引用 2 楼 linjimu 的回复:
两个函数:

VB.NET code

  Public Sub DrawControl(ByVal _Control As Control, ByVal _Bitmap As Bitmap)
        _Control.DrawToBitmap(_Bitmap, _Control.Bounds)
        For Each childControl As Control ……


感谢2楼,这个方法我测试了,可以用。
但是当容器生成图片的时候,就会同时生成容器内部的控件,
而递归之后,控件就一共生成2次,并且遍历控件的那次生成的位置不正确。
谢谢,至少给我提供了一个思路。
补充:.NET技术 ,  VB.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,