Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot access a disposed object...

Status
Not open for further replies.

Appollo14

Technical User
Joined
Sep 4, 2003
Messages
182
Location
GB
named "PrintPreviewDialog".

Hi All,

I feel like a right royal pain at the minute but I've tried looking every where to reolve the above problem.

The error occurs after i've loaded a form that contains a picture box done a print preview closed the preview, moved to the next record and attempted to preview the next image.

Any ideas??

Thanks,
Noel.
 
Could you show the code where you are previewing the image, closing the preview and then previewing the next image?



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
Hi Jebenson,

here's the code for the print preview routine;

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

Dim ImgX As Integer
Dim ImgY As Integer
Dim PSizeX As Integer
Dim PSizeY As Integer
Dim ScaleX As Double
Dim ScaleY As Double
Dim RecX As Integer
Dim RecY As Integer
Dim ScaleM As Double
Dim TopM As Integer
Dim LeftM As Integer

ImgX = Me.bxImageView.Image.Height
ImgY = Me.bxImageView.Image.Width
If Me.PrintDocument1.DefaultPageSettings.Landscape = False Then
PSizeX = Me.PrintDocument1.DefaultPageSettings.PaperSize.Height
PSizeY = Me.PrintDocument1.DefaultPageSettings.PaperSize.Width
Else
PSizeX = Me.PrintDocument1.DefaultPageSettings.PaperSize.Width
PSizeY = Me.PrintDocument1.DefaultPageSettings.PaperSize.Height
End If
ScaleX = PSizeX / ImgX
ScaleY = PSizeY / ImgY
If ScaleX < ScaleY Then
ScaleM = ScaleX
Else : ScaleM = ScaleY
End If
RecY = ImgY * ScaleM
RecX = ImgX * ScaleM
e.Graphics.DrawImage(bxImageView.Image, 0, 0, RecY, RecX)
'MessageBox.Show("IX " & ImgX & " IY " & ImgY & " PX " & PSizeX & " PY " & " SX " & ScaleX & " SY " & ScaleY & " SM " & ScaleM & " RX " & RecX & " RY " & RecY)
End Sub

Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem6.Click
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.Show()
End Sub
End Class


and here is the code for the loading the image;

Private Sub NavigateImages()
Try
Dim buffer() As Byte = CheckDBNull(CType(DSImg.Tables("ImageFilter").Rows(0).Item(1), Byte()))
Dim str As New MemoryStream(buffer)
bxImageView.Image = CheckDBNull(Image.FromStream(str))
Me.lblCount.Text = "Image " & Inc + 1 & " of " & MaxRows
Catch ex As Exception
MessageBox.Show("Sorry there are no images for this contact", "No Images", MessageBoxButtons.OK)
Me.Close()
End Try
If Inc = 0 Then
Me.btnPrevImage.Enabled = False
Me.btnFirstImage.Enabled = False
Else : Me.btnPrevImage.Enabled = True
Me.btnFirstImage.Enabled = True
End If
If Inc = MaxRows - 1 Then
Me.btnNextImage.Enabled = False
Me.btnLastImage.Enabled = False
Else : Me.btnNextImage.Enabled = True
Me.btnLastImage.Enabled = True
End If

End Sub

Regards,
Noel.
 
I think i've managed to resolve it with a simplified version of something i'd tried earlier.

I tracked the problem to the last bit of code in the print routine so i simply changed it to this.

Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem6.Click
Dim printpreviewdialog1 As New PrintPreviewDialog
Try
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.Show()
Catch ex As Exception
MessageBox.Show(ex.ToString & "3")
End Try
End Sub

it seems that adding a new instance of the dialog sorts the problem.

Thanks for looking anyway.

Regards,
Noel.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top