Results 1 to 4 of 4

Thread: Form Background image?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Form Background image?

    Ok, I have a jpg that is really small, so I want to tile it on the form like is done on webpages and windows wallpaper. I've heard I need to do this with bitblt. What is the easiest way to tile a background image onto a form. Any help or examples are extremely appreciated.

  2. #2
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    There are several ways to do it, but the easiest will be as you said, using bitblt.

    I don't have the code, but here's basically what you need to do.

    1) bitblt takes needs x, y coordinates in pixels, so you have to either change the scalemode of your form to vbPixels or use convert twips to pixels. I think it's twipsperpixelx and twipsperpixely

    2) Either set your form for autoredraw or put the tiling function in the Form_Paint sub.

    3) Use two loops, i and j.

    VB Code:
    1. For i = 1 to scalewidth step step image.width
    2.     for j = 1 to scaleheight step image.height
    3.        bitblt at x, y
    4.     next j
    5. next i
    You'll need to paste the bitblt API into your form declarations. I don't remember the arguments, but basically you put the pic you want to use in a picture box and then copy from the picture box to the x, y coordinates. You shouldn't have too many problems getting the code working.

  3. #3
    Megatron
    Guest
    Try:
    VB Code:
    1. Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
    2.  
    3. Private Sub Form_Load()
    4.     ScaleMode = 3
    5.     Picture1.AutoRedraw = True
    6.     Me.AutoRedraw = True
    7.    
    8.     For x = 0 To Width Step Picture1.Width
    9.         For y = 0 To Height Step Picture1.Height
    10.             DoEvents
    11.             BitBlt hDC, x, y, Picture1.Width, Picture1.Height, Picture1.hDC, 0, 0, vbSrcCopy
    12.         Next y
    13.     Next x
    14. End Sub

  4. #4
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    Megatron's code is what I was talking about, but use scaleheight and scalewidth instead of height and width.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width