Inherited Form

Posted on 2004-10-28
Last Modified: 2010-04-24
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?
Question by:f_asmaa
    LVL 27

    Expert Comment

    Have you tried using the full path of your bmp?
    LVL 69

    Expert Comment

    by:Éric Moreau
    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()
    LVL 85

    Accepted Solution

    This gets rid of the error but then you can only see the BackgroundImage at runtime and not at designtime:

    Public Class Form2
        Inherits Form1

    End Class

    Public Class Form1
        Inherits System.Windows.Forms.Form

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If Not Me.DesignMode Then
                Me.BackgroundImage = Image.FromFile("a.bmp")
            End If
        End Sub

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim f2 As New Form2
        End Sub
    End Class
    LVL 8

    Expert Comment

    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")
        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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    This video Micro Tutorial is the second in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 ( But the ability to create custom scanning profiles a…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    913 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now