ControlEventArgsとは? わかりやすく解説

ControlEventArgs クラス

ControlAdded イベントと ControlRemoved イベントデータ提供します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Class ControlEventArgs
    Inherits EventArgs
Dim instance As ControlEventArgs
public class ControlEventArgs : EventArgs
public ref class ControlEventArgs : public
 EventArgs
public class ControlEventArgs extends EventArgs
public class ControlEventArgs extends
 EventArgs
解説解説
使用例使用例

次のコード例では、ControlAdded イベントControlRemoved イベント使用方法示します。この例では、2 つButton コントロールフォーム追加されており、addControl_Click および removeControl_Click の各イベント処理メソッド関連付けられている必要があります

' This example demonstrates the use of the ControlAdded and
' ControlRemoved events. This example assumes that two Button controls
 
' are added to the form and connected to the addControl_Click and 
' removeControl_Click event-handler methods.
Private Sub Form1_Load(ByVal
 sender As Object, ByVal
 e As System.EventArgs) Handles MyBase.Load
    ' Connect the ControlRemoved and ControlAdded event handlers to
 the event-handler methods.
    ' ControlRemoved and ControlAdded are not available at design time.
    AddHandler Me.ControlRemoved, AddressOf
 Me.Control_Removed
    AddHandler Me.ControlAdded, AddressOf
 Me.Control_Added
End Sub 'Form1_Load


Private Sub Control_Added(ByVal
 sender As Object, ByVal
 e As System.Windows.Forms.ControlEventArgs)
    MessageBox.Show(("The control named " + e.Control.Name
 + " has been added to the form."))
End Sub


Private Sub Control_Removed(ByVal
 sender As Object, ByVal
 e As System.Windows.Forms.ControlEventArgs)
    MessageBox.Show(("The control named " + e.Control.Name
 + " has been removed from the form."))
End Sub


' Click event handler for a Button control. Adds a TextBox to the form.
Private Sub addControl_Click(ByVal
 sender As Object, ByVal
 e As System.EventArgs) Handles button1.Click
    ' Create a new TextBox control and add it to the form.
    Dim textBox1 As New
 TextBox()
    textBox1.Size = New Size(100, 10)
    textBox1.Location = New Point(10, 10)
    ' Name the control in order to remove it later. 
    ' The name must be specified if a control is added at run time.
    textBox1.Name = "textBox1"

    ' Add the control to the form's control collection.
    Me.Controls.Add(textBox1)
End Sub


' Click event handler for a Button control.
' Removes the previously added TextBox from the form.
Private Sub removeControl_Click(ByVal
 sender As Object, ByVal
 e As System.EventArgs) Handles button2.Click
    ' Loop through all controls in the form's control collection.
    Dim tempCtrl As Control
    For Each tempCtrl In
 Me.Controls
        ' Determine whether the control is textBox1,
        ' and if it is, remove it.
        If tempCtrl.Name = "textBox1"
 Then
            Me.Controls.Remove(tempCtrl)
        End If
    Next tempCtrl
End Sub
// This example demonstrates the use of the ControlAdded and
// ControlRemoved events. This example assumes that two Button controls
// are added to the form and connected to the addControl_Click and
// removeControl_Click event-handler methods.
private void Form1_Load(object sender, System.EventArgs
 e)
{
    // Connect the ControlRemoved and ControlAdded event handlers
    // to the event-handler methods.
    // ControlRemoved and ControlAdded are not available at design time.
    this.ControlRemoved += new System.Windows.Forms.ControlEventHandler(this.Control_Removed);
    this.ControlAdded += new System.Windows.Forms.ControlEventHandler(this.Control_Added);
}

private void Control_Added(object sender, System.Windows.Forms.ControlEventArgs
 e)
{
    MessageBox.Show("The control named " + e.Control.Name + " has
 been added to the form.");
}

private void Control_Removed(object sender,
 System.Windows.Forms.ControlEventArgs e)
{
    MessageBox.Show("The control named " + e.Control.Name + " has
 been removed from the form.");
}

// Click event handler for a Button control. Adds a TextBox to the form.
private void addControl_Click(object sender,
 System.EventArgs e)
{
    // Create a new TextBox control and add it to the form.
    TextBox textBox1 = new TextBox();
    textBox1.Size = new Size(100,10);
    textBox1.Location = new Point(10,10);
    // Name the control in order to remove it later. The name must be
 specified
    // if a control is added at run time.
    textBox1.Name = "textBox1";

    // Add the control to the form's control collection.
    this.Controls.Add(textBox1);
}

// Click event handler for a Button control.
// Removes the previously added TextBox from the form.
private void removeControl_Click(object sender,
 System.EventArgs e)
{
    // Loop through all controls in the form's control collection.
    foreach (Control tempCtrl in this.Controls)
    {
        // Determine whether the control is textBox1,
        // and if it is, remove it.
        if (tempCtrl.Name == "textBox1")
        {
            this.Controls.Remove(tempCtrl);
        }
    }
}
   // This example demonstrates the use of the ControlAdded and
   // ControlRemoved events. This example assumes that two Button controls
   // are added to the form and connected to the addControl_Click and
   // removeControl_Click event-handler methods.
private:
   void Form1_Load( Object^ /*sender*/, System::EventArgs^ /*e*/
 )
   {
      // Connect the ControlRemoved and ControlAdded event handlers
      // to the event-handler methods.
      // ControlRemoved and ControlAdded are not available at design
 time.
      this->ControlRemoved += gcnew System::Windows::Forms::ControlEventHandler(
 this, &Form1::Control_Removed );
      this->ControlAdded += gcnew System::Windows::Forms::ControlEventHandler(
 this, &Form1::Control_Added );
   }

   void Control_Added( Object^ /*sender*/, System::Windows::Forms::ControlEventArgs^
 e )
   {
      MessageBox::Show( String::Format( "The control named {0} has been added
 to the form.", e->Control->Name ) );
   }

   void Control_Removed( Object^ /*sender*/, System::Windows::Forms::ControlEventArgs^
 e )
   {
      MessageBox::Show( String::Format( "The control named {0} has been removed
 from the form.", e->Control->Name ) );
   }

   // Click event handler for a Button control. Adds a TextBox to the
 form.
   void addControl_Click( Object^ /*sender*/, System::EventArgs^
 /*e*/ )
   {
      // Create a new TextBox control and add it to the form.
      TextBox^ textBox1 = gcnew TextBox;
      textBox1->Size = System::Drawing::Size( 100, 10 );
      textBox1->Location = Point(10,10);

      // Name the control in order to remove it later. The name must be
 specified
      // if a control is added at run time.
      textBox1->Name = "textBox1";

      // Add the control to the form's control collection.
      this->Controls->Add( textBox1 );
   }

   // Click event handler for a Button control.
   // Removes the previously added TextBox from the form.
   void removeControl_Click( Object^ /*sender*/, System::EventArgs^
 /*e*/ )
   {
      // Loop through all controls in the form's control collection.
      IEnumerator^ myEnum = this->Controls->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         Control^ tempCtrl = safe_cast<Control^>(myEnum->Current);
         
         // Determine whether the control is textBox1,
         // and if it is, remove it.
         if ( tempCtrl->Name->Equals( "textBox1"
 ) )
         {
            this->Controls->Remove( tempCtrl );
         }
      }
   }
// This example demonstrates the use of the ControlAdded and
// ControlRemoved events. This example assumes that two Button controls
// are added to the form and connected to the addControl_Click and
// removeControl_Click event-handler methods.
private void Form1_Load(Object sender, System.EventArgs
 e)
{
    // Connect the ControlRemoved and ControlAdded event handlers
    // to the event-handler methods.
    // ControlRemoved and ControlAdded are not available at design time.
    this.add_ControlRemoved(new System.Windows.Forms.
        ControlEventHandler(this.Control_Removed));
    this.add_ControlAdded(new System.Windows.Forms.
        ControlEventHandler(this.Control_Added));
} //Form1_Load

private void Control_Added(Object sender, System.Windows.Forms.
    ControlEventArgs e)
{
    MessageBox.Show("The control named " + e.get_Control().get_Name() 
        + " has been added to the form.");
} //Control_Added

private void Control_Removed(Object sender,
 System.Windows.Forms.
    ControlEventArgs e)
{
    MessageBox.Show("The control named " + e.get_Control().get_Name() 
        + " has been removed from the form.");
} //Control_Removed

// Click event handler for a Button control. Adds a TextBox to the form.
private void addControl_Click(Object sender,
 System.EventArgs e)
{
    // Create a new TextBox control and add it to the form.
    TextBox textBox1 = new TextBox();
    textBox1.set_Size(new Size(100, 10));
    textBox1.set_Location(new Point(10, 10));

    // Name the control in order to remove it later. 
    // The name must be specified
    // if a control is added at run time.
    textBox1.set_Name("textBox1");

    // Add the control to the form's control collection.
    this.get_Controls().Add(textBox1);
} //addControl_Click

// Click event handler for a Button control.
// Removes the previously added TextBox from the form.
private void removeControl_Click(Object sender,
 System.EventArgs e)
{
    // Loop through all controls in the form's control collection.
    for (int iCtr = 0; iCtr < this.get_Controls().get_Count();
 iCtr++) {
        Control tempCtrl = this.get_Controls().get_Item(iCtr);
        
        // Determine whether the control is textBox1,
        // and if it is, remove it.
        if (tempCtrl.get_Name().Equals("textBox1"))
 {
            this.get_Controls().Remove(tempCtrl);
        }
    }
} //removeControl_Click
継承階層継承階層
System.Object
   System.EventArgs
    System.Windows.Forms.ControlEventArgs
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ControlEventArgs メンバ
System.Windows.Forms 名前空間
ControlEventHandler
Control.ControlAdded イベント
Control.ControlRemoved イベント

ControlEventArgs コンストラクタ

指定したコントロールの ControlEventArgs クラス新しインスタンス初期化します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

使用例使用例

次のコード例では、ControlAdded イベントと ControlRemoved イベント使用方法示します。この例では、2 つButton コントロールフォーム追加されており、addControl_Click および removeControl_Click の各イベント処理メソッド関連付けられている必要があります

' This example demonstrates the use of the ControlAdded and
' ControlRemoved events. This example assumes that two Button controls
 
' are added to the form and connected to the addControl_Click and 
' removeControl_Click event-handler methods.
Private Sub Form1_Load(ByVal
 sender As Object, ByVal
 e As System.EventArgs) Handles MyBase.Load
    ' Connect the ControlRemoved and ControlAdded event handlers to
 the event-handler methods.
    ' ControlRemoved and ControlAdded are not available at design time.
    AddHandler Me.ControlRemoved, AddressOf
 Me.Control_Removed
    AddHandler Me.ControlAdded, AddressOf
 Me.Control_Added
End Sub 'Form1_Load


Private Sub Control_Added(ByVal
 sender As Object, ByVal
 e As System.Windows.Forms.ControlEventArgs)
    MessageBox.Show(("The control named " + e.Control.Name
 + " has been added to the form."))
End Sub


Private Sub Control_Removed(ByVal
 sender As Object, ByVal
 e As System.Windows.Forms.ControlEventArgs)
    MessageBox.Show(("The control named " + e.Control.Name
 + " has been removed from the form."))
End Sub


' Click event handler for a Button control. Adds a TextBox to the form.
Private Sub addControl_Click(ByVal
 sender As Object, ByVal
 e As System.EventArgs) Handles button1.Click
    ' Create a new TextBox control and add it to the form.
    Dim textBox1 As New
 TextBox()
    textBox1.Size = New Size(100, 10)
    textBox1.Location = New Point(10, 10)
    ' Name the control in order to remove it later. 
    ' The name must be specified if a control is added at run time.
    textBox1.Name = "textBox1"

    ' Add the control to the form's control collection.
    Me.Controls.Add(textBox1)
End Sub


' Click event handler for a Button control.
' Removes the previously added TextBox from the form.
Private Sub removeControl_Click(ByVal
 sender As Object, ByVal
 e As System.EventArgs) Handles button2.Click
    ' Loop through all controls in the form's control collection.
    Dim tempCtrl As Control
    For Each tempCtrl In
 Me.Controls
        ' Determine whether the control is textBox1,
        ' and if it is, remove it.
        If tempCtrl.Name = "textBox1"
 Then
            Me.Controls.Remove(tempCtrl)
        End If
    Next tempCtrl
End Sub
// This example demonstrates the use of the ControlAdded and
// ControlRemoved events. This example assumes that two Button controls
// are added to the form and connected to the addControl_Click and
// removeControl_Click event-handler methods.
private void Form1_Load(object sender, System.EventArgs
 e)
{
    // Connect the ControlRemoved and ControlAdded event handlers
    // to the event-handler methods.
    // ControlRemoved and ControlAdded are not available at design time.
    this.ControlRemoved += new System.Windows.Forms.ControlEventHandler(this.Control_Removed);
    this.ControlAdded += new System.Windows.Forms.ControlEventHandler(this.Control_Added);
}

private void Control_Added(object sender, System.Windows.Forms.ControlEventArgs
 e)
{
    MessageBox.Show("The control named " + e.Control.Name + " has
 been added to the form.");
}

private void Control_Removed(object sender,
 System.Windows.Forms.ControlEventArgs e)
{
    MessageBox.Show("The control named " + e.Control.Name + " has
 been removed from the form.");
}

// Click event handler for a Button control. Adds a TextBox to the form.
private void addControl_Click(object sender,
 System.EventArgs e)
{
    // Create a new TextBox control and add it to the form.
    TextBox textBox1 = new TextBox();
    textBox1.Size = new Size(100,10);
    textBox1.Location = new Point(10,10);
    // Name the control in order to remove it later. The name must be
 specified
    // if a control is added at run time.
    textBox1.Name = "textBox1";

    // Add the control to the form's control collection.
    this.Controls.Add(textBox1);
}

// Click event handler for a Button control.
// Removes the previously added TextBox from the form.
private void removeControl_Click(object sender,
 System.EventArgs e)
{
    // Loop through all controls in the form's control collection.
    foreach (Control tempCtrl in this.Controls)
    {
        // Determine whether the control is textBox1,
        // and if it is, remove it.
        if (tempCtrl.Name == "textBox1")
        {
            this.Controls.Remove(tempCtrl);
        }
    }
}
   // This example demonstrates the use of the ControlAdded and
   // ControlRemoved events. This example assumes that two Button controls
   // are added to the form and connected to the addControl_Click and
   // removeControl_Click event-handler methods.
private:
   void Form1_Load( Object^ /*sender*/, System::EventArgs^ /*e*/
 )
   {
      // Connect the ControlRemoved and ControlAdded event handlers
      // to the event-handler methods.
      // ControlRemoved and ControlAdded are not available at design
 time.
      this->ControlRemoved += gcnew System::Windows::Forms::ControlEventHandler(
 this, &Form1::Control_Removed );
      this->ControlAdded += gcnew System::Windows::Forms::ControlEventHandler(
 this, &Form1::Control_Added );
   }

   void Control_Added( Object^ /*sender*/, System::Windows::Forms::ControlEventArgs^
 e )
   {
      MessageBox::Show( String::Format( "The control named {0} has been added
 to the form.", e->Control->Name ) );
   }

   void Control_Removed( Object^ /*sender*/, System::Windows::Forms::ControlEventArgs^
 e )
   {
      MessageBox::Show( String::Format( "The control named {0} has been removed
 from the form.", e->Control->Name ) );
   }

   // Click event handler for a Button control. Adds a TextBox to the
 form.
   void addControl_Click( Object^ /*sender*/, System::EventArgs^
 /*e*/ )
   {
      // Create a new TextBox control and add it to the form.
      TextBox^ textBox1 = gcnew TextBox;
      textBox1->Size = System::Drawing::Size( 100, 10 );
      textBox1->Location = Point(10,10);

      // Name the control in order to remove it later. The name must be
 specified
      // if a control is added at run time.
      textBox1->Name = "textBox1";

      // Add the control to the form's control collection.
      this->Controls->Add( textBox1 );
   }

   // Click event handler for a Button control.
   // Removes the previously added TextBox from the form.
   void removeControl_Click( Object^ /*sender*/, System::EventArgs^
 /*e*/ )
   {
      // Loop through all controls in the form's control collection.
      IEnumerator^ myEnum = this->Controls->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         Control^ tempCtrl = safe_cast<Control^>(myEnum->Current);
         
         // Determine whether the control is textBox1,
         // and if it is, remove it.
         if ( tempCtrl->Name->Equals( "textBox1"
 ) )
         {
            this->Controls->Remove( tempCtrl );
         }
      }
   }
// This example demonstrates the use of the ControlAdded and
// ControlRemoved events. This example assumes that two Button controls
// are added to the form and connected to the addControl_Click and
// removeControl_Click event-handler methods.
private void Form1_Load(Object sender, System.EventArgs
 e)
{
    // Connect the ControlRemoved and ControlAdded event handlers
    // to the event-handler methods.
    // ControlRemoved and ControlAdded are not available at design time.
    this.add_ControlRemoved(new System.Windows.Forms.
        ControlEventHandler(this.Control_Removed));
    this.add_ControlAdded(new System.Windows.Forms.
        ControlEventHandler(this.Control_Added));
} //Form1_Load

private void Control_Added(Object sender, System.Windows.Forms.
    ControlEventArgs e)
{
    MessageBox.Show("The control named " + e.get_Control().get_Name() 
        + " has been added to the form.");
} //Control_Added

private void Control_Removed(Object sender,
 System.Windows.Forms.
    ControlEventArgs e)
{
    MessageBox.Show("The control named " + e.get_Control().get_Name() 
        + " has been removed from the form.");
} //Control_Removed

// Click event handler for a Button control. Adds a TextBox to the form.
private void addControl_Click(Object sender,
 System.EventArgs e)
{
    // Create a new TextBox control and add it to the form.
    TextBox textBox1 = new TextBox();
    textBox1.set_Size(new Size(100, 10));
    textBox1.set_Location(new Point(10, 10));

    // Name the control in order to remove it later. 
    // The name must be specified
    // if a control is added at run time.
    textBox1.set_Name("textBox1");

    // Add the control to the form's control collection.
    this.get_Controls().Add(textBox1);
} //addControl_Click

// Click event handler for a Button control.
// Removes the previously added TextBox from the form.
private void removeControl_Click(Object sender,
 System.EventArgs e)
{
    // Loop through all controls in the form's control collection.
    for (int iCtr = 0; iCtr < this.get_Controls().get_Count();
 iCtr++) {
        Control tempCtrl = this.get_Controls().get_Item(iCtr);
        
        // Determine whether the control is textBox1,
        // and if it is, remove it.
        if (tempCtrl.get_Name().Equals("textBox1"))
 {
            this.get_Controls().Remove(tempCtrl);
        }
    }
} //removeControl_Click
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

ControlEventArgs プロパティ


パブリック プロパティパブリック プロパティ

参照参照

関連項目

ControlEventArgs クラス
System.Windows.Forms 名前空間
ControlEventHandler
Control.ControlAdded イベント
Control.ControlRemoved イベント

ControlEventArgs メソッド


ControlEventArgs メンバ

ControlAdded イベントと ControlRemoved イベントデータ提供します

ControlEventArgs データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド ControlEventArgs 指定したコントロールの ControlEventArgs クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

ControlEventArgs クラス
System.Windows.Forms 名前空間
ControlEventHandler
Control.ControlAdded イベント
Control.ControlRemoved イベント


このページでは「.NET Framework クラス ライブラリ リファレンス」からControlEventArgsを検索した結果を表示しています。
Weblioに収録されているすべての辞書からControlEventArgsを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からControlEventArgs を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ControlEventArgs」の関連用語

ControlEventArgsのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ControlEventArgsのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS