Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Inherited Form

Posted on 2004-10-28
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 27

Expert Comment

ID: 12436057
Have you tried using the full path of your bmp?
LVL 70

Expert Comment

by:Éric Moreau
ID: 12436058
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 86

Accepted Solution

Mike Tomlinson earned 2000 total points
ID: 12436083
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

Expert Comment

ID: 12436113
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.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

636 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