前端之家收集整理的这篇文章主要介绍了
植物大战僵尸,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Public Class Form1 Private txt As Text
Box Private bt As Button '植物与僵尸数组 Private Pt(2) As Button Private Js(2) As Button '定义泡泡 Private pp As Button Dim j As Integer Sub New() ' 此
调用是 Windows 窗体设计器所必需的。 InitializeComponent() ' 在 InitializeComponent()
调用之后
添加任何初始化。 End Sub Private Sub Button2_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button2.Click '
添加三个植物 Dim i As Integer = 0 For i = 0 To 2 Pt(i) = New Button Pt(i).FlatStyle = FlatStyle.Flat Pt(i).Text = "" Pt(i).Size = New Size(120,108) Pt(i).BackgroundImage = Image.FromFile("pt" & i & ".jpg") Pt(i).BackgroundImageLayout = ImageLayout.Stretch Pt(i).Location = New Point(2,54 + 130 * i) Me.Controls.Add(Pt(i)) Pt(i).Show() Next End Sub Private Sub Button3_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button3.Click '
添加三个僵尸 Dim i As Integer = 0 For i = 0 To 2 Js(i) = New Button Js(i).FlatStyle = FlatStyle.Flat Js(i).Text = "" Js(i).Size = New Size(120,108) Js(i).BackgroundImage = Image.FromFile("js" & i & ".jpg") Js(i).BackgroundImageLayout = ImageLayout.Stretch Js(i).Location = New Point(590,54 + 130 * i) Me.Controls.Add(Js(i)) Js(i).Show() Next End Sub Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click '示例化控件对象 txt = New Text
Box() bt = New Button() '为对象设置关键一些
属性 txt.Location = New Point(100,100) txt.Size = New Size(200,20) txt.BackColor = Color.Chocolate bt.Location = New Point(100,150) bt.Size = New Size(102,35) bt.Text = "确 定" '将定义控件
添加到窗体 ,并
显示 Me.Controls.Add(txt) Me.Controls.Add(bt) txt.Show() : bt.Show() '控件
添加完毕 '为控件
添加事件 AddHandler bt.Click,AddressOf btClk AddHandler txt.KeyPress,AddressOf txtKPR End Sub Private Sub txtKPR(ByVal sender As Object,ByVal e As System.Windows.Forms.KeyPressEventArgs) '当按回车时等同于按确认按钮 If e.KeyChar = Microsoft.VisualBasic.Chr(13) Then Msg
Box("欢迎你," & txt.Text) End If End Sub Private Sub btClk(ByVal sender As System.Object,ByVal e As System.EventArgs) Msg
Box("欢迎你," & txt.Text) End Sub Private Sub Button4_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button4.Click '发泡泡 pp = New Button() pp.Text = "" pp.FlatStyle = FlatStyle.Flat pp.Location = New Point(110,350) pp.Size = New Size(50,20) pp.BackgroundImageLayout = ImageLayout.Stretch pp.BackgroundImage = Image.FromFile("pp.jpg") Me.Controls.Add(pp) pp.Show() Timer1.Enabled = True End Sub Private Sub Timer1_Tick(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Timer1.Tick j = j + 10 pp.Location = New Point(110 + j,350) End Sub Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load j = 0 Me.Text = "植物大战僵尸" End Sub End Class