• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 162
  • Last Modified:

Form not unloading after assigning a picture to an Image control

My About box's Form_Load contains the following line of code:

imgIcon.Picture = frmMain.Icon

to display main form's icon in an Image control. When I close the dialog and then close my program, the About box is not unloaded, so the program does not really end. I've commented out that line and then the program ends correctly. The same happens with PictureBox controls. Any hints?
0
luisr
Asked:
luisr
  • 4
  • 4
1 Solution
 
AzraSoundCommented:
to ensure you are closing all forms do this:

Private Sub Form_Unload(Cancel As Integer)
    Dim frm As Form
    For Each frm In Forms
        If frm.hWnd <> Me.hWnd Then _
            Unload frm
    Next
    Unload Me
End Sub

0
 
luisrAuthor Commented:
That would do it, but I still want to know why the form is still loaded after a call to Unload Me.

BTW, I'm using VB 5.0.
0
 
AzraSoundCommented:
I would imagine because he is referencing the icon from your main form which is not unloaded yet.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
luisrAuthor Commented:
I tried imgIcon.Picture = LoadPicture() before unloading the form and it did not work.
0
 
AzraSoundCommented:
try this:

Set imgIcon.Picture = Nothing
0
 
luisrAuthor Commented:
It does not work.
0
 
AzraSoundCommented:
why dont you just do as i stated earlier and close all the forms?  are you saying that you close the about box and then close the main form and then the about box form suddenly reappears?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
You line
imgIcon.Picture = frmMain.Icon
will load the form "frmMain" (into memory), in order to be able to access the icon data.
So it is the frmMain that remains loaded, not the About form!
If you want to unload that form, you need to add a line like
Unload frmMain
immediately after your first line.

Hope this illuminates you
0
 
luisrAuthor Commented:
You're right angelIII, it's frmMain that remains in memory. Although your solution works (unloading frmMain), I did something else. I changed my code to copy the icon from the global variable fMainForm, which is an instance of frmMain.

Thanks for the tip!!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now