Changing Background Pictures

Cheetah

Well-known member
Joined
Oct 12, 2006
Messages
232
Programming Experience
Beginner
Hi there,

How can i speed up the time it takes to change background pictures of controls and forms.

There is always a slight delay for me?

I have added the images to my resources.

Is there anyway i can like "load" it into memory so that its quicker?

Thanks.
 
1. Add a module named Module1 to your project.

2. Declare a public bitmap in the module:
Public bmp as Bitmap

3. In the startup form, in the Load event handler, put the following line:
Module1.bmp = Image.FromFile("C:\01.jpg")

4. In the same startup form, in the Disposed event handler, put the following line:
Module1.bmp.Dispose()

5. In the form where you want the image beeing displayed put the following statement in the Load event handler:
BackgroundImage = Module1.bmp

_________________________________________________

I'm not sure it will help too much.

Other ideeas:

1. If your computer isn't a very fast one, the solution should be obvious.

2. Try to disable your antivirus. Antiviruses dramatically slow down file accesses. If this helps, replace your antivirus with another one. But, generally speaking, you don't need an antivirus if you run applications only from serious sources and visit only serious web sites (like this one).

3. You may have lots of nice applications installed on your computer. You used them once then forgot about them. Uninstalling them will not help too much, their uninstallers frequently "forget" to remove resource consumming parts. The ideal solution is to reinstall everything but skip all those nice applications. Keep their installation kits and install them only when you really need them.
Same applies for device drivers for devices you use rarely (a digital photo camera you use 3 times a year or that scanner you used once two years ago.)

4. Errors in the phase of hard drive partitionning can result in a working, but very slow partition. I don't mean errors made by you, sometimes the disk utilities are able to make them without your help. Run chkdsk, the Disk Manager, other disk utilities you may have, and check very carefully for any anomaly you may see.

5. You may have viruses (well... not you... your computer).

6. You may use the wrong programming techniques. If you suspect any sequence of code to be too slow, put it in a For/Next loop, repeat it 1,000 times and watch the time. If it executes too fast, repeat it 100,000 times or 10,000,000 times. (If you create new objects in the loop, don't forget to dispose them before the end of the loop otherwise your computer may run out of resources.)

7. While working with the Visual Studio, don't keep 53 Internet Explorer windows open.

8. Add more memory
 
Last edited:
One thing that might help is storing an image scaled to fit your form (in the OnResize event) so that the form you can set the BackGroundImageLayout to tile. This will avoid the scaling operation from happening when you assign the BackgroundImage.

Otherwise, you could try handling the OnPaint event to paint it manually, set the double buffered property to true and call SetStyle(ControlStyles.UserPaint) and SetStyle(ControlStyles.ResizeRedraw). That might allow you gain some milliseconds. In the OnPaint event, use e.Graphics.DrawImage(My.Resources.MyImage, me.ClientRectangle).

Else than this, I don't know what to try... Maybe someone else would have more pointers...
 
Back
Top