|
-
May 15th, 2002, 05:02 PM
#1
Thread Starter
Fanatic Member
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.
-
May 15th, 2002, 05:23 PM
#2
PowerPoster
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:
For i = 1 to scalewidth step step image.width
for j = 1 to scaleheight step image.height
bitblt at x, y
next j
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.
-
May 15th, 2002, 05:30 PM
#3
Try:
VB Code:
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
Private Sub Form_Load()
ScaleMode = 3
Picture1.AutoRedraw = True
Me.AutoRedraw = True
For x = 0 To Width Step Picture1.Width
For y = 0 To Height Step Picture1.Height
DoEvents
BitBlt hDC, x, y, Picture1.Width, Picture1.Height, Picture1.hDC, 0, 0, vbSrcCopy
Next y
Next x
End Sub
-
May 15th, 2002, 05:39 PM
#4
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|