How to get a screen capture of a .Net WinForms control programmatically?

前端 未结 7 2052
抹茶落季
抹茶落季 2020-12-13 09:30

How do you programmatically obtain a picture of a .Net control?

7条回答
  •  一向
    一向 (楼主)
    2020-12-13 10:10

    Panel1.Dock = DockStyle.None ' If Panel Dockstyle is in Fill mode
    Panel1.Width = 5000  ' Original Size without scrollbar
    Panel1.Height = 5000 ' Original Size without scrollbar
    
    Dim bmp As New Bitmap(Me.Panel1.Width, Me.Panel1.Height)
    Me.Panel1.DrawToBitmap(bmp, New Rectangle(0, 0, Me.Panel1.Width, Me.Panel1.Height))
    'Me.Panel1.DrawToBitmap(bmp, Panel1.ClientRectangle)
    bmp.Save("C:\panel.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
    
    Panel1.Dock = DockStyle.Fill
    

    Note: Its working fine

提交回复
热议问题