I have a simple form that, when the user clicks on a hyperlink, the image file path is passed to the form's OpenArgs and the form displays the image in full size.
The code goes like this:
(I think there's a potential problem to this code, like it might choke if the image to display is larger than the screen, but I'll deal with that separately)
I was just thinking that, if all the properties of this form are defined by code, and the only button in there is a CloseButton class module that closes its parent form, then maybe I can just create this form on the fly, and kill it when the user closes it.
I'm sure a form can be created programmatically, but delete it after use?
I don't know if this is a good idea, just wondering how to do it.
The code goes like this:
Code:
Option Compare Database
Option Explicit
Dim clsClose As clsCloseButton
Private Sub Form_Load()
Set clsClose = New clsCloseButton
clsClose.Init_Button Me.btnClose
Dim oImg As Object
Set oImg = CreateObject("WIA.ImageFile")
oImg.LoadFile Me.OpenArgs
With Me
'Resize the window using the Move command, set the width to that of the image, 1 pixel = 15 twips
.Move .WindowLeft, , Width:=oImg.Width * 15
'Adjust the height by setting the Detail section of the form, then setting the InsideHeight to match
'Add a little strip at the bottom for the Close button
.Detail.Height = oImg.Height * 15 + .btnClose.Height
.InsideHeight = .Detail.Height
.Picture = Nz(Me.OpenArgs, "")
.PictureAlignment = 0 'Top left
.PictureSizeMode = 0 'Clip mode
.btnClose.Top = .Detail.Height
.btnClose.Left = (oImg.Width * 15 - .btnClose.Width) / 2 'Center the button
End With
Set oImg = Nothing
End Sub
I was just thinking that, if all the properties of this form are defined by code, and the only button in there is a CloseButton class module that closes its parent form, then maybe I can just create this form on the fly, and kill it when the user closes it.
I'm sure a form can be created programmatically, but delete it after use?
I don't know if this is a good idea, just wondering how to do it.