截取绘制的面板的屏幕截图

时间:2014-02-06 17:31:28

标签: c# screenshot

我有一个面板,我已经动态地绘制了几个形状,文本和添加的图片框。我想截取面板的截图,以便保存。我尝试了下面的代码,但它只给了我面板的背景图像和子控件,缺少图纸。救命啊!

Bitmap bit = new Bitmap(pnlKanvas.Width, pnlKanvas.Height);
pnlKanvas.DrawToBitmap(bit, new Rectangle(0, 0, bit.Width, bit.Height));

1 个答案:

答案 0 :(得分:0)

使用CreateGraphics调用绘制图像/位图。使用该位图作为面板的背景图像,然后执行您正在尝试的...

添加代码..

Dim img As Image = New Bitmap(1500, 1500)
Dim g As Graphics = Graphics.FromImage(img)

'Do what ever you have done using ... abc.CreateGraphics.Something() as g.Something()
'see below

g.Clear(Color.White)
g.DrawImage(fpicGear(piIndex + 1).picGear, lTempXpos, lTempYpos)
g.DrawString(tString, New Font("Arial", 8, FontStyle.Regular), brushColor, New Point(lXTextPosition, lYTextPosition))
myPanel.BackgroundImage = img