VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Easy tiled-image form backgrounds

by Tom Honaker (3 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (43 Votes)


This code, which was inspired by a similar snippet of code by Ian Ippolito, permits tiling an image onto a form's background. This variant, though, resides in a module and is called by a form instead of residing within the form's code itself. This permits using the feature project-wide without redundant code all over the place.

Inputs
Three inputs are required in the actual sub call: frm: The name of the form to tile an image onto picholder: The name of a PictureBox control on that same form, which will be used to hold the image to tile. (See the explanation for required settings) bkgdfile: The image file to load, with complete path. The best place to put the call I find is in the form's Form_Paint() event.
Assumes
To use this code, you'll need to create a PictureBox control on your target form and set its AutoRedraw, AutoSize, and ClipControls properties to TRUE, and its Visible property to FALSE. When you call the sub, you'll be passing the form's name and the name of this PictureBox to the sub.
Code Returns
Nothing returned.
Side Effects
Larger forms (read: INSANELY large forms) might take some time to refresh on slow systems. Also, very small images take noticeably longer to tile than larger ones, so aim for about 125x125 pixel sizes for the tilable images. Finally, although this code can use GIFs, interlaced GIFs tend to produce a single-pixel horizontal banding effect. So convert 'em to non-interlaced, etc. Also, this does NOT work on MDI parent forms, although it works great on MDI child forms.
API Declarations

Rate Easy tiled-image form backgrounds


Sub TileBkgd(frm As Form, picholder As PictureBox, bkgdfile As String)
  If bkgdfile = "" Then Exit Sub
  Dim ScWidth%, ScHeight%, ScMode%, n%, o%
  
  ScMode% = frm.ScaleMode
  picholder.ScaleMode = 3
  frm.ScaleMode = 3
  picholder.Picture = LoadPicture(bkgdfile)
  picholder.ScaleMode = 3
  For n% = 0 To frm.Height Step picholder.ScaleHeight
    For o% = 0 To frm.Width Step picholder.ScaleWidth
      frm.PaintPicture picholder.Picture, o%, n%
    Next o%
  Next n%
  frm.ScaleMode = ScMode%
  picholder.Picture = LoadPicture()
End Sub

Download this snippet    Add to My Saved Code

Easy tiled-image form backgrounds Comments

No comments have been posted about Easy tiled-image form backgrounds. Why not be the first to post a comment about Easy tiled-image form backgrounds.

Post your comment

Subject:
Message:
0/1000 characters