Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add background picture to a VB Form? 1

Status
Not open for further replies.

josephlai

Technical User
Aug 7, 2002
8
MO
Hi, I want to add a cascaded background image to my VB Form. (like those on a webpage background). I add a .bmp using the "picture" property of the form but the image appear in the upper left corner only. How can I fill the whole Form with the picture?

Thanks for any help.
Joseph.
 
I think you'll have to tile pictureboxes that contain your picture.


Greetings,
Rick
 
Place a picturebox on your form.

Load the tile picture in the picture property of that picturebox.

Paste the following code and run the program to test it.
___
Private Sub Form_Load()
Picture1.Visible = False
Picture1.AutoSize = True
AutoRedraw = True
Dim X As Integer, Y As Integer
For X = 0 To Screen.Width Step Picture1.ScaleWidth
For Y = 0 To Screen.Height Step Picture1.ScaleHeight
PaintPicture Picture1.Picture, X, Y
Next
Next
AutoRedraw = False
End Sub
 
if you do want to stretch a picture rather than tile you can do something like this:-

again load the picture into the picture box at development time.

Private Sub Form_Load()
Picture1.Visible = False
Picture1.AutoRedraw = True
Picture1.AutoSize = True
Form1.AutoRedraw = True
Form1.WindowState = vbMaximized
End Sub

Private Sub Form_Activate()
Form1.PaintPicture Picture1.Picture, 0, 0, _
Form1.ScaleWidth, Form1.ScaleHeight, _
0, 0, Picture1.ScaleWidth, _
Picture1.ScaleHeight, vbSrcCopy
Form1.Refresh
End Sub

bear in mind if the picture is to small the pixels will be massive when stretched!!

good luck!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
oops i put the code in the wrong event...

the code should read

Private Sub Form_Load()
Picture1.Visible = False
Picture1.AutoRedraw = True
Picture1.AutoSize = True
Form1.AutoRedraw = True
Form1.WindowState = vbMaximized
End Sub

Private Sub Form_Resize()
Form1.PaintPicture Picture1.Picture, 0, 0, _
Form1.ScaleWidth, Form1.ScaleHeight, _
0, 0, Picture1.ScaleWidth, _
Picture1.ScaleHeight, vbSrcCopy
Form1.Refresh
End Sub

sorry for the confusion!!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
ADoozer, it will be a nice idea to call the PaintPicture method in Resize event instead of Activate event.
 
LOL

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top