?? form1.frm
字號(hào):
VERSION 5.00
Begin VB.Form Form1
Caption = "動(dòng)態(tài)創(chuàng)建控件"
ClientHeight = 3720
ClientLeft = 60
ClientTop = 345
ClientWidth = 5055
LinkTopic = "Form1"
ScaleHeight = 3720
ScaleWidth = 5055
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command2
Caption = "刪除控件"
Height = 495
Left = 240
TabIndex = 1
Top = 1080
Width = 975
End
Begin VB.CommandButton Command1
Caption = "添加控件"
Height = 495
Left = 240
TabIndex = 0
Top = 240
Width = 975
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private WithEvents NewButton As CommandButton
Attribute NewButton.VB_VarHelpID = -1
'通過(guò)使用WithEvents關(guān)鍵字聲明一個(gè)對(duì)象變量為新的命令按鈕
Private Sub Command1_Click()
If NewButton Is Nothing Then
Set NewButton = Controls.Add("VB.CommandButton", "cmdNew", Form1)
'增加新的按鈕cmdNew
NewButton.Move Command1.Left + Command1.Width + 240, Command1.Top
'確定新增按鈕cmdNew的位置
NewButton.Caption = "動(dòng)態(tài)添加的按鈕"
NewButton.Visible = True
'顯示該按鈕
End If
End Sub
Private Sub Command2_Click()
If NewButton Is Nothing Then
Exit Sub
Else
Controls.Remove NewButton
Set NewButton = Nothing
End If
End Sub
Private Sub NewButton_click()
MsgBox "這是動(dòng)態(tài)增加的按鈕,你可以單擊“刪除控件”按鈕刪除它", vbDefaultButton1, "Click"
End Sub
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -