植物大战僵尸

Public Class Form1
    Private txt As TextBox
    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 TextBox()
        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
            MsgBox("欢迎你," & txt.Text)
        End If


    End Sub


    Private Sub btClk(ByVal sender As System.Object, ByVal e As System.EventArgs)
        MsgBox("欢迎你," & 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
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

发哥1997

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值