动态添加控件

来源:互联网 发布:js如何获取css的样式 编辑:程序博客网 时间:2024/04/27 22:06

Option Explicit

    '通过使用 WithEvents 关键字声明一个对象变量为新的命令按钮

    Private WithEvents Newbox As CommandButton


    '增加控件

    Private Sub Command1_Click()

    If Newbox Is Nothing Then

    '增加新的按钮boxnew

    Set Newbox = Controls.Add("VB.CommandButton", "boxnew", Me)

    '确定新增按钮boxnew的位置
 
   
    Newbox.Move Text1.Left + Text1.Width + 240 + Text1.Top

    Newbox.Caption = "新增的按钮"

    Newbox.Visible = True

    End If

    End Sub

原创粉丝点击