AddControl 事件、Add 方法範例
下列範例會使用 Add 方法,在執行時間將控制項新增至表單,並使用 AddControl 事件來確認已新增控制項。
若要使用本範例,請將此範例程式碼複製到表單的宣告部分中。 請確定該表單包含:
- 一個名為 CommandButton1 的 CommandButton 。
- 一個名為 Label1 的 Label 。
Dim Mycmd as Control
Private Sub CommandButton1_Click()
Set Mycmd = Controls.Add("MSForms.CommandButton.1") ', CommandButton2, Visible)
Mycmd.Left = 18
Mycmd.Top = 150
Mycmd.Width = 175
Mycmd.Height = 20
Mycmd.Caption = "This is fun." & Mycmd.Name
End Sub
Private Sub UserForm_AddControl(ByVal Control As _
MSForms.Control)
Label1.Caption = "Control was Added."
End Sub
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應