Welcome to Foxite.COM Community Weblog Sign in | Join | Help

Bernard Bout

May the Fox be with you...

<October 2008>
SuMoTuWeThFrSa
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

Post Categories

News

site statistics

Locations of visitors to this page

Navigation

Some VFP links

Others...

Archives

Who links to this site?

Hey There!!!

Syndication




Interesting Animated Background Effect for Forms

Most of you have seen the effect of the Vista dialogs where the background of the form appears to move whe the form is moved. While difficult to describe, it is easy to see and even easier to implement for your forms.

Obviously if you have Vista, then you already have the animated background effect. So this post is aimed at those of us who have upgraded to and still use XP.

This effect is achieved with just 2 lines of code as you will see.

Click on either of the images below to view it at full size and right click and "Save Picture as" somewhere - backgroung.jpg

  or  

This will be your background for your form.

So create a new form and drop an image control on it. Make sure you click on it and "Send to Back" or in its INIT add the line

This.Zorder(0)

to make sure it is always the rearmost item on your form. Now you can either assign the above picture you downloaded as its Picture property or do that in the Form.Init. I prefer the latter:

Form::Init

ThisForm.Image1.Picture = "background.jpg"

Now to get this animation effect you will need only the following 2 lines of code: So open the Form.Moved and add this code exactly as shown:

WITH This.Image1

     .Left = -ThisForm.left

     .Top = -ThisForm.Top

ENDWITH

And yes, that is -Thisform.Left (minus thisform.left) &  (minus thisform.Top)

Run the form and see that the form now has the background you set. Now move the form and observe the background appears to move when the form is moved.

And there you have it - an animated background for your form A la Vista with just 2 lines of code. You can also load the above background image into any Paint application and change the colours to suit your theme or make up one of your own.

Unfortunately because of the amount of junk mail being generated from the weblog I have switched off comments. Please post your comments, if any, at www.foxite.com

Published Thursday, October 23, 2008 11:41 AM by bbout

Comments

# re: Interesting Animated Background Effect for Forms @ Thursday, October 23, 2008 10:56 AM

neatly :-)

Andrzej

# re: Interesting Animated Background Effect for Forms @ Thursday, October 23, 2008 12:41 PM

Good one
Thanks for sharing.

Imran

# re: Interesting Animated Background Effect for Forms @ Thursday, October 23, 2008 3:55 PM

Bernard:

I guess you forgot some other settings, how is it that the image control covers the whole form? Do we set the Stretch property to something? How about the Anchor property?

Nope I did not forget anything. The image, if you downloaded it, is 1280x1024 which is big enough for most screens. If needed it can be made bigger. Since the image object has its stretch property = CLIP(default), the image object stretches automatically when the image is loaded to display the whole image. Besides you cannot use the Anchor property for this. All you need is a large enough background image. And the two lines of code.

Carlos Alloatti

# re: Interesting Animated Background Effect for Forms @ Thursday, October 23, 2008 4:18 PM

Simply splendid!
Now tell me... hod did ya find this ???

A-M-A-Z-I-N-G !!!!!!!!

Thanks Cesar. Just fooling around with forms and images and it suddenly came to me. It surprised me too considering I don't have vista, only XP. The effect was too good to keep to myself.

Cesar

# re: Interesting Animated Background Effect for Forms @ Thursday, October 23, 2008 4:20 PM

Nice demonstration of a very cool effect! You could do it in one line of code. ;)

THIS.Image1.Move(-ThisForm.left,-ThisForm.Top)

Very True and a nice one there.

In order to completely encapsulate the functionality into a class, you could place this code in the image.init

THIS.ZOrder(0)
THIS.Move(0,0,THISFORM.Width, THISFORM.Height)
THIS.Picture = "backgroundblue.jpg"
BINDEVENT(THISFORM,"Moved",THIS,"Move")

and these lines in the image.move

LPARAMETERS m.nLeft, m.nTop, m.nWidth, m.nHeight
RETURN DODEFAULT(-THISFORM.Left,-THISFORM.Top)

The encapsulation (and bindevent of course) permits anyone to drop this image class on any form and have it work without customizing form code.

Mike Yearwood

Sure Mike and thanks for the excellent suggestion. It is actually the idea that I wanted to share, not any code implementation, hence there is no usual download except the images. As to its implementation, I leave that to whoever wants to use this idea however they want to implement it. Anyway you have given an implementation of the idea that anyone can use or adapt.

Mike Yearwood

# re: Interesting Animated Background Effect for Forms @ Tuesday, October 28, 2008 5:30 AM

My mistake, I right-cliked on the little image and saved it as secondarythumb.aspx.jpg, did not read carefully, to first click to get the large image.

No worries. Glad you got it to work.

Carlos Alloatti

# re: Interesting Animated Background Effect for Forms @ Thursday, October 30, 2008 12:06 PM

Nice idea, I just added these lines in the form's init:
With This.image1
  .Width=SYSMETRIC(1)
  .Height=SYSMETRIC(2)
  .Stretch= 2
Endwith

This way I make sure the image on the back is always big enough for the _screen (I work on two 24" monitors.)

BL

BL

Your comments are much appreciated.

I am almost sure, like Carlos, you did not read the post properly. The images I posted are 1280x1024 which are large enough for most monitors. Of course you have to go and get 2x 24" monitors and confuse the issue.Smile [:)] It is better to resize the image than to stretch it as some effect is always lost and the strain on resources goes up. Also the image is not distorted by the stretch. But your point is also valid.

boudewijn Lutgerink

# re: Interesting Animated Background Effect for Forms @ Thursday, October 30, 2008 2:37 PM

IN addition to my previous post, You should set the width of the image pbject to
sysmetric(1)*2 and the height to sysmetric(2)*2
As you move the picture in the opposite direction of the left and/or top of the form you should actually adjust the width and height of the image accordingly.

Again I can only assume that you have downloaded the thumbnail image and not the real image that you can access just by clicking the thumbnail and "SaveAs" since there is no need for all this stretching at all with a large image.

boudewijn Lutgerink

# re: Interesting Animated Background Effect for Forms @ Monday, November 03, 2008 5:35 PM

Damn you're good, Bernard...

Smile [:)]

Johan Ballet

# re: Interesting Animated Background Effect for Forms @ Monday, November 10, 2008 6:33 AM

O Jeezzz ... thank u !

If you liked that then how about this:

http://weblogs.foxite.com/bernardbout/archive/2008/11/07/7249.aspx

meidy

New Comments to this post are disabled
Powered by Community Server, by Telligent Systems