Anda di halaman 1dari 14

Creating New Project

Modifying Properties of Form

\
Inserting Buttons

Adding Resources

Changing background of buttons


Adding Module
'Form1.vb*
Public Class Form1
Private Sub b1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles b1.Click
'24
cblev1(b1, b2)
cblev1(b1, b4)
Fnlev1()
End Sub

Private Sub b2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles b2.Click
'135
cblev1(b2, b1)
cblev1(b2, b3)
cblev1(b2, b5)
Fnlev1()
End Sub

Private Sub b3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles b3.Click
'26
cblev1(b3, b2)
cblev1(b3, b6)
Fnlev1()
End Sub

Private Sub b4_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles b4.Click
'157
cblev1(b4, b1)
cblev1(b4, b5)
cblev1(b4, b7)
Fnlev1()
End Sub

Private Sub b5_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles b5.Click
'2468
cblev1(b5, b2)
cblev1(b5, b4)
cblev1(b5, b6)
cblev1(b5, b8)
Fnlev1()
End Sub

Private Sub b6_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles b6.Click
'359
cblev1(b6, b3)
cblev1(b6, b5)
cblev1(b6, b9)
Fnlev1()
End Sub

Private Sub b7_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles b7.Click
'48
cblev1(b7, b4)
cblev1(b7, b8)
Fnlev1()
End Sub

Private Sub b8_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles b8.Click
'579
cblev1(b8, b5)
cblev1(b8, b7)
cblev1(b8, b9)
Fnlev1()
End Sub

Private Sub b9_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles b9.Click
'68
cblev1(b9, b6)
cblev1(b9, b8)
Fnlev1()
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles


MyBase.Load
'declaring randomized funtion
rLev1()
End Sub
End Class
'Module1.vb*
Module Module1
Sub cblev1(ByRef Bt1 As Button, ByRef Bt2 As Button)
If Bt2.Text = "" Then
Bt2.Text = Bt1.Text
Bt2.BackgroundImage = Bt1.BackgroundImage

Bt1.Text = ""
Bt1.BackgroundImage = Nothing

End If
End Sub

Sub Fnlev1()
If Form1.b1.Text = "1" And Form1.b2.Text = "2" And Form1.b3.Text =
"3" And Form1.b4.Text = "4" And Form1.b5.Text = "5" And Form1.b6.Text
= "6" And
Form1.b7.Text = "7" And Form1.b8.Text = "8" And Form1.b9.Text
= "" Then
MsgBox("WOW! YOU WIN!!!")
End If
End Sub

Sub rLev1()
Dim ti(8), a, b, ran As Integer
Dim fg As Boolean
fg = False
a=1
ti(b) = 1
Do While a <= 8
Randomize()
ran = CInt(Int((8 * Rnd()) + 1))
For b = 1 To a
If ti(b) = ran Then
fg = True
Exit For

End If
Next
If fg = True Then
fg = False
Else
ti(a) = ran
a=a+1
End If

Loop

Form1.b1.Text = ti(1)
Form1.b1.BackgroundImage =
System.Drawing.Image.FromFile("C:\Users\Acer E 14 Core
i5\Pictures\Picture Puzzle\" & ti(1) & ".jpg")
Form1.b2.Text = ti(2)
Form1.b2.BackgroundImage =
System.Drawing.Image.FromFile("C:\Users\Acer E 14 Core
i5\Pictures\Picture Puzzle\" & ti(2) & ".jpg")
Form1.b3.Text = ti(3)
Form1.b3.BackgroundImage =
System.Drawing.Image.FromFile("C:\Users\Acer E 14 Core
i5\Pictures\Picture Puzzle\" & ti(3) & ".jpg")
Form1.b4.Text = ti(4)
Form1.b4.BackgroundImage =
System.Drawing.Image.FromFile("C:\Users\Acer E 14 Core
i5\Pictures\Picture Puzzle\" & ti(4) & ".jpg")
Form1.b5.Text = ti(5)
Form1.b5.BackgroundImage =
System.Drawing.Image.FromFile("C:\Users\Acer E 14 Core
i5\Pictures\Picture Puzzle\" & ti(5) & ".jpg")
Form1.b6.Text = ti(6)
Form1.b6.BackgroundImage =
System.Drawing.Image.FromFile("C:\Users\Acer E 14 Core
i5\Pictures\Picture Puzzle\" & ti(6) & ".jpg")
Form1.b7.Text = ti(7)
Form1.b7.BackgroundImage =
System.Drawing.Image.FromFile("C:\Users\Acer E 14 Core
i5\Pictures\Picture Puzzle\" & ti(7) & ".jpg")
Form1.b8.Text = ti(8)
Form1.b8.BackgroundImage =
System.Drawing.Image.FromFile("C:\Users\Acer E 14 Core
i5\Pictures\Picture Puzzle\" & ti(8) & ".jpg")
Form1.b9.Text = ""
End Sub

End Module
Running the program each time, the puzzle pieces are randomly arranged

Winning the game


Adding a panel and modifying its properties

Initializing function to view the panel

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles


MyBase.Load
'declaring randomized funtion
rLev1()
ViewPictureToolStripMenuItem.Text = "View Picture"
Panel1.Visible = False

Adding a menustrip
Double clicking Random and adding the random function

Private Sub RandomToolStripMenuItem_Click_1(sender As Object, e As


EventArgs) Handles RandomToolStripMenuItem.Click
rLev1()
End Sub

Double clicking View Picture and creating a function to view the panel

Private Sub ViewPictureToolStripMenuItem_Click(sender As Object, e As


EventArgs) Handles ViewPictureToolStripMenuItem.Click
If ViewPictureToolStripMenuItem.Text = "Hide Picture" Then
ViewPictureToolStripMenuItem.Text = "View Picture"
Panel1.Visible = False
Else
ViewPictureToolStripMenuItem.Text = "Hide Picture"
Panel1.Visible = True

End If
End Sub

Running the program

Double clicking About and creating a function

Private Sub AboutToolStripMenuItem_Click(sender As Object, e As


EventArgs) Handles AboutToolStripMenuItem.Click
MsgBox(
"Activity 2 in OOP
Submitted by:
DALEON
DANIEL
MARTINEZ")

End Sub

Double clicking Exit and creating a function

Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs)


Handles ExitToolStripMenuItem.Click
Close()

End Sub

Running the program

Anda mungkin juga menyukai