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
Solved

Painting a forms background

Posted on 1998-09-04
10
401 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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
 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

856 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