开发者

Taking too much time to load the application in vb.net

开发者 https://www.devze.com 2022-12-27 18:42 出处:网络
i a开发者_运维百科m 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 c

i a开发者_运维百科m 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


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消