Just from what you wrote, I don't think what you are trying to do is a
good idea. Isn't it really up to the client to decide the lifetime of the
graphic image and whether its supposed to be disposed?
Yes but see below
How and when can you enforce this rule? Unless you force the user to call
a method (Dispose or Close) in your class, but then how is your class going
to know the client did not call your class's Dispose or Close method before
setting its own reference to your object to Nothing?
Maybe I'm missing something?
I doubt it!
But he should never program anything that would cause AdjustDocumentImage to
execute because it deletes the bitmap the graphic object points to and
creates a new one.
If he does and there is an active reference to the Graphic object it will
be pointing to the deleted Bitmap
How about the following just to catch a programming error?
Public ReadOnly Property PicCreateGraphics() As Graphics
'Client should dispose this
Get
PicCreateGraphics = Graphics.FromImage(mDocumentImage)
mPicCreateGraphicsSaved = PicCreateGraphics 'Saved so I can later check to
see if it is still valid
End Get
End Property
Private Sub AdjustDocumentImage()
Try
Dim zz = mPicCreateGraphicsSaved.DpiX 'GO TO CATCH IF GRAPHIC REFERENCE IS
NG
MessageBox.Show("Can not adjust image if Graphics object is active",
"Error", Message-snip
Catch
'THIS WHERE TH GOOD CODE GOES
DELETE mDocumentImage BITMAP
Why am I deleteing the Bitmap?? Because I want to change its size (at the
client request - he should make sure he does not have an active graphics
object at this time) while preserving the contents. The only way I know how
to do that is to make a new one and get rid of the old one.
Boy if I just change the size of the current one that would be great - but
I've no idea how to do that.
Thanks for your reply