0

i am using vb.net in which i have put the background image to every form.the image size is 1024X768.when i open the form it is taking too much time to open. and screen is fluctuate.so can you tell me how to remove this type of issue,

reply me soon thanks samir

Samir
  • 605
  • 3
  • 9
  • 14
  • Sounds like the problem may be your computer. Try running the application on another computer and see if it's still loading slow. – slim Apr 17 '10 at 12:15
  • Does every form use the same image for the background, or does each form have its own unique image? – MusiGenesis Apr 17 '10 at 12:26
  • i have tried in other PC also.its taking too much loading time and there is only one image in all forms. – Samir Apr 17 '10 at 12:29
  • Possible duplicate: http://stackoverflow.com/questions/2454111/label-backgrond-flicking-on-a-winforms-user-control-has-background-image-enabled – Hans Passant Apr 17 '10 at 13:03

1 Answers1

1

I'm assuming (hoping) you're not setting the BackgroundImage property of each form in the designer, as this would mean that your executable's size would be at least 3 MB times the total number of forms.

So you probably have code in the form's Load event or its constructor to load the BackgroundImage from a file or an embedded resource. This would mean you'd take the hit of loading a 3 MB image file every time you create and display a form.

There are different ways to do something like this, but whatever you do you want to make sure that you only load this file into a Bitmap once in the lifetime of your program and then re-use it for every form. A simple way to enable this is to modify each form's constructor (except for your main form) to take a Bitmap as a parameter and set this as the form's BackgroundImage:

public SomeForm(Bitmap backgroundImage)
{
    this.BackgroundImage = backgroundImage;
}

In your main form's Load event, you would create a Bitmap and load it (with your one big image) from wherever and set it as the main form's BackgroundImage:

this.BackgroundImage = Bitmap.FromFile('yadda.bmp');

Then, whenever you create and show another form, you do it like this:

SomeForm sform = new SomeForm(this.BackgroundImage);
sform.Show();

This approach will ensure that your program only takes the hit of loading this file into memory once, when your main form loads. Some proportion of the delay you're seeing is due to the time it takes to render the image (as opposed to the time it takes to load it from disk), so this may not fix all of your problem. May I suggest not having a huge image as the background for every form in your application?

MusiGenesis
  • 74,184
  • 40
  • 190
  • 334