Solved

Painting a forms background

Posted on 1998-09-04
10
397 Views
Last Modified: 2010-04-30
The time that it takes to paint a forms background is far to long.  This is how I am doing it.
First I load the picture into a Picture Box control that is hidden on the form.  Then using the height and width of the Picture Box I tile the forms background using the appropriate x and y coordinates.  This works very well and is extremely fast especially if the picture is small.
My problem begins when I want to apply a picture that is 1024x768 to the form.  Obviously there is no need to tile since the resolution I use is also 1024x768.  But it seems like it takes forever to load the control with the picture and equally as long to paint the form.  I have tried painting the form directly with the picture and not loading the Picture Box but while this takes half the time, it is still far to slow.  By slow I mean 1 second up to as much as 5 seconds.  The lag is barely noticeable on a P-II but since the typical platform this will be running on is a Pentium-200, I need to find a way to speed this up.
Any comments, questions or suggestions will greatly appreciated.
0
Comment
Question by:MalcolmPike
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 7

Expert Comment

by:kamall
ID: 1433135
Since you have a fast CPU, make your pictures in .JPG format and load them. They will load and show very fast on the form. Load them directly on the form (not in the picture box).
Hope that helps.
Regards
0
 

Author Comment

by:MalcolmPike
ID: 1433136
I did forget to inform all that the pictures are all in JPG format.  While all pictures that are 1024x768 in size are painted directly on the form the smaller graphics need to be placed in the picture box so that I will know what the dimensions are and therfore tile the forms background.  
The problem is only with the large 1024x768 JPG pictures.  They are small in size, only 80k to 125k.  But even when I load them directly on the form it still takes anywhere from 2 to 5 seconds before the job is done.
0
 
LVL 2

Expert Comment

by:wj7ster
ID: 1433137
Can you perhaps list the code that you used to do that.  Are you using the 'PaintPicture' method?
0
 

Author Comment

by:MalcolmPike
ID: 1433138
When I tile the form I use the 'PaintPicture' method. (This works great).
But when I try to paint the entire forms background with a JPG that is of the same size (1024x768), I simply use
"Me.Picture = LoadPicture(Pic)".
Where 'Pic' = the path and file name of the JPG.
Again I do not load the picture into a PictureBox first if it is 1024x768 so it seems that all the time is used doing the painting.
Is there a faster method?

Any help is greatly appreciated.

0
 
LVL 2

Expert Comment

by:wj7ster
ID: 1433139
Malcolm,

This code disable/enable updating/redrawing of the form.  This could speed it up, maybe.

Declare the following API:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_SETREDRAW = &HB

Before you load the picture to the form, disable updating for the form:

   SendMessage Form1.hWnd, WM_SETREDRAW, False, 0 ' disable redraw

   ' load the picture here and apply to the form's picture property...

   SendMessage Form1.hWnd, WM_SETREDRAW, True, 0 ' enable redraw

It could be neccessary to do a Form1.Refresh afterwards, but first try without it.

Because this is API calls, be carefull with them, make sure you don't have any errors, or if you have, that you always turn on redrawing of the form (error handling).

Hope this can help.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:MalcolmPike
ID: 1433140
I did everything as explained by wj7ster but unfortunately it did not increase the speed.  FYI: I did have to do the form refresh in order to see the background.
Is there an API that I can call to paint the background?  Or any method that is faster?
It must have to do with the physical size of the graphic because I can tile the background with a jpg that is for example one inch by one inch instantaneously.

Thanks in advance.

0
 

Expert Comment

by:jwhowell
ID: 1433141
Is this for a splash, or somewhere in the middle of your app.?  If in the middle, try creating an instance of the form during the sub main (don't use the main form as a starting point for your app.)  Then you are using the 'splash' time to load the image and all you do is frmMyForm.show !

Jason
0
 

Author Comment

by:MalcolmPike
ID: 1433142
The painting of the single forms background can happen many times during the forms life.  
What is going on is this;
I am using one form to display many options or questions to the user.  Once the user has answered the question then the next question is shown.  If the new question has a background different than the previous question then I have to repaint the form.
Using two or more forms is not really an option for me unless I am absolutly forced to do so.

Thanks to Jason.


0
 
LVL 2

Accepted Solution

by:
kswinney earned 150 total points
ID: 1433143
If you don't mind purchasing a third-party control, the Lead Technologies image control supports progressive JPEG.  You could save your images as progressive JPEG, then load the progressive JPEG at runtime, giving [the appearance of] faster load time.

After all... perception is reality.

Also... Lead Technologies' loading of JPEG files is faster than Native VB anyway.

0
 
LVL 2

Expert Comment

by:kswinney
ID: 1433144
Another thing to consider, MalcolmPike, is to load all the images necessary for your app at load time into StdPicture (Picture) objects... preferably an array of Picture objects.

Then, use the .Render method to paint them on the form as the user needs to see them.

This way, the load time is all on the front end.  The performance while using the app will be acceptable.

HTH.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 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

13 Experts available now in Live!

Get 1:1 Help Now