⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.vb

📁 vb 应用实例 简单应用 ddddddddddddddddddddddddddddddddd
💻 VB
字号:
Imports System.Xml

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form  "

    Public Sub New()
        MyBase.New()

        InitializeComponent()


    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    Private components As System.ComponentModel.IContainer

    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Button3 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.Button2 = New System.Windows.Forms.Button()
        Me.Button3 = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(20, 16)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(113, 24)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "添加TextBox"
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(20, 56)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(113, 24)
        Me.Button2.TabIndex = 1
        Me.Button2.Text = "添加Button"
        '
        'Button3
        '
        Me.Button3.Location = New System.Drawing.Point(20, 96)
        Me.Button3.Name = "Button3"
        Me.Button3.Size = New System.Drawing.Size(113, 24)
        Me.Button3.TabIndex = 2
        Me.Button3.Text = "清除控件"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(440, 142)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button3, Me.Button2, Me.Button1})
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "在程序中添加控件"
        Me.ResumeLayout(False)

    End Sub

#End Region


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

      

        intCount += 1

        

        If intCount <= 3 Then

           
            Dim t As New TextBox()

           
            t.Text = "活在当下!"
            t.Name = "t"
            t.Location = New Point(m_Location.X + 120, m_Location.Y)
            t.Size = New Size(200, t.Height)

            
            Controls.Add(t)

            m_Location.Y += t.Height + 18

        Else
            MsgBox("只能新增加3个。", MsgBoxStyle.OKOnly, Me.Text)

        End If

    End Sub

    Private intCount As Integer = 0
    Private m_Location As New Point(10, 16)

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        
        intCount += 1

        
        If intCount <= 3 Then
           
            Dim x As New Button()

           
            x.Name = "btn" + intCount.ToString()
            x.Text = "我是老 " + intCount.ToString()
            x.Size = New Size(88, 24)
            x.Location = New Point(Me.m_Location.X + 120, Me.m_Location.Y)
            m_Location.Y += x.Height + 18

           
            AddHandler x.Click, AddressOf NewButtonHandler_Click
            AddHandler x.MouseHover, AddressOf NewButtonHandler_MouseHover

           
            Controls.Add(x)
        Else
            MsgBox("只能添加3个, 试着用鼠标点击新的控件.", MsgBoxStyle.OKOnly, Me.Text)
        End If

    End Sub

    
    Private Sub NewButtonHandler_Click(ByVal sender As Object, ByVal e As EventArgs)
        
        If TypeOf sender Is Button Then
            MsgBox("点击 " & CType(sender, Button).Text, MsgBoxStyle.OKOnly, Me.Text)
        End If
    End Sub

    
    Private Sub NewButtonHandler_MouseHover(ByVal sender As Object, ByVal e As EventArgs)
        
        If TypeOf sender Is Button Then
            MsgBox("鼠标飞越过 " & CType(sender, Button).Text, MsgBoxStyle.OKOnly, Me.Text)
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        
        Controls.Clear()

        InitializeComponent()

        intCount = 0
        m_Location = New Point(10, 16)

    End Sub


 

End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -