Class Tscrollform (unit Scrlform) |
TForm
Instructions for using the Scrolling Background template: Saving in the Form Gallery: To save this form in the gallery that pops up when you add a new form to your project, follow the instructions under Delphi help: search for templates -> Saving a Form as a Template. This basically tells you to open up this file, then display it's form. Then, right click on the form to bring up the pop-up menu and select "Save as Template". For the title, type in "Scrolling Background" and for the description you can type in "New Form With a Scrolling Bitmap Background". I have included an icon bitmap called "template.bmp" to use as the thumbnail image. Using the Scrolling Background form: This form gets the background image from a resource file, which I've included. When you select this form from the gallery, this resource file is not copied into your project directory. You need to do this manually. The resource file is called "IMAGES.RES". Note that this is a seperate file than the resource file "xx.RES" ("xx" is the name of your project), which is the project resource file used by Delphi. This file is overwritten during the compilation of the program, so you cannot store your bitmaps in it. The file is linked to your executable by the compiler resource directives: Existing line --> {$R *.DFM} Added line --> {$R IMAGES.RES} This will link your resource file to the project during compilation. The resource file has 9 bitmaps in it. You can edit these bitmaps with the Delphi Image Editor or create your own resource file with other images. Changing the sign of "xmovement" and "ymovement" changes the scrolling direction of the bitmap. The absolute value of these varibles is the number of pixels the bitmap moves per timer firing. The form has not been debugged at values greater than one, so increase these at your own risk! Change the line: SetImage('BITMAP_1'); in the OnCreate method to load other bitmaps. There are 19 bitmaps in the resource file, ordered sequentially from BITMAP_1 to BITMAP_19. Other features: The form has an exception handling procedure built in to handle any errors during the form's run. You can take this out without affecting the form. The background bitmap name and scrolling direction are declared as constants. You should make these variables if you wish to change the background during run time. If you just want a background without it scrolling, you can remove all the timer code. Be sure to leave the resizing and painting code intact. Possible improvements: Some components don't look too good on the form itself, such as labels. If you need to use a label on your form, I would recommend putting it on (in??) a panel component so you can see it before it's overwritten. My demo version of this form allows you to load a bitmap from a file during runtime for use as a background. It also allows you to include a bitmap file name on the command line and it starts up with that bitmap as a background. Performance: The background scrolls smoothly with a full screen form on a 486-100mhz running Windows95 w/32 meg RAM using the default settings. Decreasing the timer interval can speed up the scrolling, but may degrade performance when the form is full screen. Disclaimer: This component is provided free of charge, and you are free to do anything with the code presented here. There is no warranty on this product and the author accepts no liability for any damage that may be caused to the user's system by this product. In other words, use at your own risk. If you have any problems or have any comments you can reach me at: mantis@vcnet.com -and- http://www.vcnet.com/mantis
Constructors |
Functions |
Set "Backimage"
Properties |
Events |
Variables |
Constructors |
Functions |
Create the form background image
Create the TBitmap and load the image from the MemoryStream
Repaint the screen
Private declarations
Set "Backimage"
Name of bitmap in resource file
Properties |
Events |
Variables |