One Picture Multiple Picturebox's
Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
3 posts
Page 1 of 1
So, as the title says, i'll teach you how to place one picture in a few picturebox's. I needed this for my 'puzzle - jigsaw' game in MMC. I made code my self and since another task is given, i'll post tutorial about it.
Do as listed:
-Create new project
-Create 9 picturebox's with same size, lets say 150,150
-Place picturebox's next to each other !
-Create 1 button and change it's text to "Choose" or "Browse" "Pick" or whatever
Open button click event and add this code
Chose whatever size you want, but if you've set 3x3 picturebox's size as 150,150 it's whole size is 450,450.
Now, add this code for each picturebox's paint event
Here is code for all picturebox's
Do as listed:
-Create new project
-Create 9 picturebox's with same size, lets say 150,150
-Place picturebox's next to each other !
-Create 1 button and change it's text to "Choose" or "Browse" "Pick" or whatever
Open button click event and add this code
Code: Select all
Also add this declaration above the Sub
Dim opfd As New OpenFileDialog
opfd.Filter = "Image Files(*.BMP;*.JPG;*.GIF;*.PNG)|*.BMP;*.JPG;*.GIF;*.PNG|All files (*.*)|*.*"
opfd.ShowDialog()
If opfd.FileName = "" Then Exit Sub
Dim img As Bitmap = Image.FromFile(opfd.FileName)
NewBmp = New Bitmap(img, 450, 450)
Code: Select all
So that it looks like this
Dim NewBmp As Bitmap
Code: Select all
So, this thing
Dim NewBmp As Bitmap
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
''
Dim opfd As New OpenFileDialog
opfd.Filter = "Image Files(*.BMP;*.JPG;*.GIF;*.PNG)|*.BMP;*.JPG;*.GIF;*.PNG|All files (*.*)|*.*"
opfd.ShowDialog()
If opfd.FileName = "" Then Exit Sub
Dim img As Bitmap = Image.FromFile(opfd.FileName)
NewBmp = New Bitmap(img, 450, 450)
End Sub
Code: Select all
What this means is sets global NewBmp to new size (450,450) NewBmp = New Bitmap(img, 450, 450)
Chose whatever size you want, but if you've set 3x3 picturebox's size as 150,150 it's whole size is 450,450.
Now, add this code for each picturebox's paint event
Code: Select all
Now, this is only for first picture box. You see this:
Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
On Error Resume Next
e.Graphics.DrawImage(NewBmp, 0, 0)
End Sub
Code: Select all
Now, this draws graphic at specified coordinates(0,0), but for next picturebox, it will be something else e.Graphics.DrawImage(NewBmp, 0, 0)
Code: Select all
The X coordinate is negative, because the picture should be drawn at point before the picturebox, now the part for that picturebox should be right.Private Sub PictureBox2_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox2.Paint
On Error Resume Next
e.Graphics.DrawImage(NewBmp, -150, 0)
End Sub
Here is code for all picturebox's
Code: Select all
Now, to button choose just add one more thing, that will draw our picture :
Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
On Error Resume Next
e.Graphics.DrawImage(NewBmp, 0, 0)
End Sub
Private Sub PictureBox2_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox2.Paint
On Error Resume Next
e.Graphics.DrawImage(NewBmp, -150, 0)
End Sub
Private Sub PictureBox3_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox3.Paint
On Error Resume Next
e.Graphics.DrawImage(NewBmp, -300, 0)
End Sub
Private Sub PictureBox4_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox4.Paint
On Error Resume Next
e.Graphics.DrawImage(NewBmp, 0, -150)
End Sub
Private Sub PictureBox5_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox5.Paint
On Error Resume Next
e.Graphics.DrawImage(NewBmp, -150, -150)
End Sub
Private Sub PictureBox6_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox6.Paint
On Error Resume Next
e.Graphics.DrawImage(NewBmp, -300, -150)
End Sub
Private Sub PictureBox7_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox7.Paint
On Error Resume Next
e.Graphics.DrawImage(NewBmp, 0, -300)
End Sub
Private Sub PictureBox8_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox8.Paint
On Error Resume Next
e.Graphics.DrawImage(NewBmp, -150, -300)
End Sub
Private Sub PictureBox9_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox9.Paint
On Error Resume Next
e.Graphics.DrawImage(NewBmp, -300, -300)
End Sub
Code: Select all
Hope you like it, if you find any bugs please let me know ;)Dim PictureBoxs() as picturebox = {PictureBox1, PictureBox2,PictureBox3,PictureBox4,PictureBox5,PictureBox6,PictureBox7,PictureBox8,PictureBox9}
'This gets all pictureBox's in a collection
For each pb as PictureBox in PictureBoxs
pb.Refresh
Next
'This refreshes each picturebox and rises Paint Event. Now our picture will be drawn.
Nice tutorial M1z23R!
Keep it up cooll;
You used the same thing for the MMDC?
Keep it up cooll;
You used the same thing for the MMDC?
Instead of LOL use this -
LSIBMHBIWFETALOL
Which means -
Laughing silently in between my head because it wasn't funny enough to actually laugh out loud!
LSIBMHBIWFETALOL
Which means -
Laughing silently in between my head because it wasn't funny enough to actually laugh out loud!
Yes, for Jigsaw game, but i added picture box moving and some other stuff
3 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023