[RESOLVED] Tile Picture in Picturebox
Ive got a form with 2 frames on it, inside the left frame is a button array. On the right side is the questions in the program. When it starts it loads the questions from a file and displays the first question, its multiple choice. You select your answer and click ok, then it displays the 2nd question, and so on... You cant view future questions, but you can view and go back to any of the previous questions. There's a scroll bar scrolling the question and button frames within a bigger frame since im using a tabstrip.
Here's the issue, im trying to make it look all graphical, but i because the size of the frames the questions are in keep getting bigger, and there's no set size, im going to make a tileable background picture for both of the frames. But i dont know how to tile it.
I figured it might be easiest to put a picturebox in the frame, and anytime the frame size is changed it will resize the picturebox to the size of the frame, and i can load a picture in the picturebox and tile it.. But there's no tile option.. So i have to do it manually.
Anybody know how to do this?
Re: Tile Picture in Picturebox
You can time images quite simple. Here is quick routing that tiles on the form so substitute form object (Me) with picturebox and you'll be all set:
Code:
Private Sub Command1_Click()
Dim img As Image
Dim h%, w%
Me.AutoRedraw = True
Me.Cls
Set img = Me.Controls.Add("VB.Image", "imgTemp")
img.Picture = LoadPicture("c:\someimage.bmp")
For h = 0 To Me.Height Step img.Height
For w = 0 To Me.Width Step img.Width
Me.PaintPicture img.Picture, w, h
Next w
Next h
Me.Controls.Remove "imgTemp"
Set img = Nothing
End Sub
Re: Tile Picture in Picturebox
ok i modified it to this:
Code:
Private Sub Command1_Click()
Dim h%, w%
For h = 0 To QSelFrame.Height Step PicHolder.Height
For w = 0 To QSelFrame.Width Step PicHolder.Width
picMidLeft.PaintPicture PicHolder.Picture, w, h
Next w
Next h
End Sub
I loaded a picture into PicHolder, and set its Visible property to false, then i put the picMidLeft inside the frame it needs to go in.. Now everytime i click the ok button, it takes the picture from PicHolder and tiles it into picMidLeft.
You had the code limited to the screen width and height, but since the number of questions is unlimited, the height of the frame can be several times the height of the form, so i used the frames width and height instead
Thanks Rhino for the code! :wave:
Re: Tile Picture in Picturebox
Quote:
Originally Posted by PMad
You had the code limited to the screen width and height...
Each form has its limitations in terms of size so I am not sure what you're referring to.
But anyway... as long as it works for you. :wave:
Re: Tile Picture in Picturebox
I'll explain a little bit for you. Lets say your screen resolution is 1280x1024, and you use the code you provided for me, here's your code but im going to highlight some parts in red:
Code:
Private Sub Command1_Click()
Dim img As Image
Dim h%, w%
Me.AutoRedraw = True
Me.Cls
Set img = Me.Controls.Add("VB.Image", "imgTemp")
img.Picture = LoadPicture("c:\someimage.bmp")
For h = 0 To Me.Height Step img.Height
For w = 0 To Me.Width Step img.Width
Me.PaintPicture img.Picture, w, h
Next w
Next h
Me.Controls.Remove "imgTemp"
Set img = Nothing
End Sub
the highlighted code is going the width and height of the current form, limiting your tileing to the width and height of the form. If the window is always maximized like in my program, and your screen resolution is 1280x1024, then this code will only tile whats visible to you, upto the width and height of your form, which is your screen resolution in my example.
This is how my form is setup:
http://img413.imageshack.us/img413/9396/framestl8.jpg
ok these controls are all set inside a frame on my form.
The white box is a frame, with a picturebox sized to the same exact size as the frame, thats why its white. Then there's a box on that white frame, thats just a button array. To the right is the questions and answers, and an ok button.
when the user clicks the ok button, the frame/picturebox is resized, only the height. Just enough to fit in another button directly to the left of the next question and answer. The purpose of that button is to go back to previous questions. Well lets say there's 100 questions. Obviously the height of that picturebox and frame are going to be far greater then the height of the form.
What will happen is after 1024 pixels high, it will stop tiling the image, and it will be the picture box's BackColor property.
so what i did, instead of using the forms width and height, i used the frames width and height, that way its limited only to the width and height of the frame, which will cause the tiling to always occur.
I hope that explanation helped hehe :eek2:
Quote:
Originally Posted by RhinoBull
Each form has its limitations in terms of size so I am not sure what you're referring to.
But anyway... as long as it works for you. :wave:
Re: [RESOLVED] Tile Picture in Picturebox
To answer you lengthy post all I can say is whatever the object is (form or picturebox ... etc) it has some boundaries.
I painted picture directly on the form so Me.Height/Width was applicable.
Same goes for picturebox if you're tiling image inside of it - container must have some size even if it gets auto sized.