Adriaan
Adriaan

Reputation: 51

Can't save panel with controls to bitmap

I have been googling my behind off all morning trying to figure this out.

I have a panel with multiple labels, a picturebox and background image. I want to save this whole panel to an bitmap for printing, however, it only draws the panel and background image. None of my labels or the picture box is being draw.

Here is my code

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    Dim bmp As New Bitmap(jobcard.Panel1.Width, jobcard.Panel1.Height)
    jobcard.Panel1.DrawToBitmap(bmp, New Rectangle(0, 0, bmp.Width, bmp.Height))
    If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
        bmp.Save(SaveFileDialog1.FileName)
    End If
End Sub

Anyone know what could cause this? P.S, I am using Visual Studio express 2012

EDIT : I got this working partly thanks to the help of Mou below. I forgot to show the form before I tried to save the panel to the bitmap. The form is hidden so I didn't really notice

Upvotes: 1

Views: 769

Answers (1)

Mou
Mou

Reputation: 16322

try this

Bitmap bmp = new Bitmap(panel1.Width,panel1.Height);
panel1.DrawToBitmap(bmp, panel1.Bounds);
bmp.Save(@"C:\Temp\Test.bmp");

got the tips from this url How can I save a Panel in my form as a picture?

i test it and it worked fine. here is the image of my panel which i generated programmatically. enter image description here

Upvotes: 1

Related Questions