graphics.hdc

Sep 25 2003 5:38 PM
Hi, I have an image in a form that i have to print. so i am trying to graphics.hdc for it. I get an error "invalid handle" at Dim dc1 As IntPtr = g.GetHdc what is the reason for this. thanks in advance. Private Sub print_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintForm.Click Me.BuildFormImage(Me.PictureBox1.CreateGraphics) PrintDialog1.Document = PrintDocument1 If PrintDialog1.ShowDialog = DialogResult.OK Then PrintDocument1.Print() End If End Sub Private Sub BuildFormImage(ByVal g As Graphics) g.DrawImage(Me.PictureBox1.Image, 0, 0) Dim buf() As Byte Dim myStream As FileStream Dim myReader As BinaryReader Dim bytesRead As Integer Try Dim dc1 As IntPtr = g.GetHdc myStream = New FileStream(dc1, FileMode.Open) ' i get an error invalid handle at this point myReader = New BinaryReader(myStream) ReDim buf(LOF(1)) bytesRead = myReader.Read(buf, 0, buf.Length) g.ReleaseHdc(dc1) MsgBox("file not found") Catch ex As Exception MsgBox(ex.ToString) End Try End Sub Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage BuildFormImage(e.Graphics) End Sub

Answers (1)