Link to home
Start Free TrialLog in
Avatar of f_asmaa
f_asmaa

asked on

Inherited Form

I have a VB.NET form that has the following line in its Load event

Me.BackgroundImage = Image.FromFile("background.bmp")

When I added an inherited form of this form I get the following error when open the inherited form in the designer:

//////////////////////////////////////
// An error occurred while loading the document. Fix the error, and then try loading the document again.
// The error message follows:
//
// background.bmp
/////////////////////////////////////

What is the problem?
Avatar of Howard Cantrell
Howard Cantrell
Flag of United States of America image

Have you tried using the full path of your bmp?
You have to be very carefull about what you put in the Load event (and some others) of base forms because these events are executed when you try to display a derived form in the IDE designer.

The solution is to create your own method (something like MyLoad) that you will call yourself just after you did the declaration:
dim x as new MyBaseFrom()
x.MyLoad
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of toddhd
toddhd

The problem is it is not finding the bitmap, for some reason. Can you post some code showing how you inherit and display the form?

optionally, you can comment out the offending line for the moment, then add something that creates a file, for instance, a text file. Like this:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Me.BackgroundImage = Image.FromFile("background.bmp")
        File.Create("WhereAmI.txt")
    End Sub

Now fire up the inherited form, and then go look for the WhereAmI.txt file, and you'll know where the app is looking to find the bitmap.