AddControl イベント、Add メソッドの例

次の例では、 Add メソッドを使用して実行時にコントロールをフォームに追加し、コントロールが追加されたことを確認するために AddControl イベントを使用します。

この例を使用するには、以下のサンプル コードをフォームの宣言部分にコピーします。 Make sure that the form contains:

  • CommandButton1 と命名された CommandButton
  • ラベル ( Label ) コントロール (Label1)
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 のサポートおよびフィードバックを参照してください。