Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Form not unloading after assigning a picture to an Image control

Posted on 2000-04-19
9
Medium Priority
?
161 Views
Last Modified: 2010-05-02
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
Comment
Question by:luisr
  • 4
  • 4
9 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2731537
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
 
LVL 3

Author Comment

by:luisr
ID: 2731846
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
 
LVL 28

Expert Comment

by:AzraSound
ID: 2731874
I would imagine because he is referencing the icon from your main form which is not unloaded yet.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 3

Author Comment

by:luisr
ID: 2731888
I tried imgIcon.Picture = LoadPicture() before unloading the form and it did not work.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2731906
try this:

Set imgIcon.Picture = Nothing
0
 
LVL 3

Author Comment

by:luisr
ID: 2731937
It does not work.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2732013
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
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 200 total points
ID: 2732072
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
 
LVL 3

Author Comment

by:luisr
ID: 2732202
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month21 days, 1 hour left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question