ContainerControl.ActiveControl ContainerControl.ActiveControl ContainerControl.ActiveControl ContainerControl.ActiveControl Property

정의

컨테이너 컨트롤에 있는 활성 컨트롤을 가져오거나 설정합니다.Gets or sets the active control on the container control.

public:
 property System::Windows::Forms::Control ^ ActiveControl { System::Windows::Forms::Control ^ get(); void set(System::Windows::Forms::Control ^ value); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Control ActiveControl { get; set; }
member this.ActiveControl : System.Windows.Forms.Control with get, set
Public Property ActiveControl As Control

속성 값

Control에서 현재 활성 상태에 있는 ContainerControl입니다.The Control that is currently active on the ContainerControl.

구현

예외

할당된 Control을 활성화할 수 없는 경우The Control assigned could not be activated.

예제

다음 코드 예제에서 상속 되는 ScrollableControl 클래스를 구현 합니다 IContainerControl 인터페이스.The following code example inherits from the ScrollableControl class and implements the IContainerControl interface. 구현에 추가 되는 ActiveControl 속성 및 ActivateControl 메서드.Implementation is added to the ActiveControl property and the ActivateControl method.

using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;

public ref class MyContainer: public ScrollableControl, public IContainerControl
{
private:
   Control^ activeControl;

public:
   MyContainer()
   {
      // Make the container control Blue so it can be distinguished on the form.
      this->BackColor = Color::Blue;

      // Make the container scrollable.
      this->AutoScroll = true;
   }

   property Control^ ActiveControl 
   {
      // Add implementation to the IContainerControl.ActiveControl property.
      virtual Control^ get()
      {
         return activeControl;
      }

      virtual void set( Control^ value )
      {
         
         // Make sure the control is a member of the ControlCollection.
         if ( this->Controls->Contains( value ) )
         {
            activeControl = value;
         }
      }
   }

   // Add implementations to the IContainerControl.ActivateControl(Control) method.
   virtual bool ActivateControl( Control^ active )
   {
      if ( this->Controls->Contains( active ) )
      {
         // Select the control and scroll the control into view if needed.
         active->Select(  );
         this->ScrollControlIntoView( active );
         this->activeControl = active;
         return true;
      }

      return false;
   }
};
using System;
using System.Windows.Forms;
using System.Drawing;

	public class MyContainer : ScrollableControl, IContainerControl
	{
		private Control activeControl;
		public MyContainer() 
		{
			// Make the container control Blue so it can be distinguished on the form.
			this.BackColor = Color.Blue;
			
			// Make the container scrollable.
			this.AutoScroll = true;
		}

		// Add implementation to the IContainerControl.ActiveControl property.
		public Control ActiveControl
		{
			get
			{
				return activeControl;
			}

			set
			{
				// Make sure the control is a member of the ControlCollection.
				if(this.Controls.Contains(value))
				{
					activeControl = value;
				}
			}
		}

		// Add implementations to the IContainerControl.ActivateControl(Control) method.
		public bool ActivateControl(Control active)
		{
			if(this.Controls.Contains(active))
			{
				// Select the control and scroll the control into view if needed.
				active.Select();
				this.ScrollControlIntoView(active);
				this.activeControl = active;
				return true;
			}
			return false;
		}
	}
Imports System.Windows.Forms
Imports System.Drawing

   Public Class MyContainerControl
      Inherits ScrollableControl
      Implements IContainerControl 

      Private myActiveControl As Control
      
      Public Sub New()
         ' Make the container control Blue so it can be distinguished on the form.
         Me.BackColor = Color.Blue
         
         ' Make the container scrollable.
         Me.AutoScroll = True
      End Sub 
      
      ' Add implementation to the IContainerControl.ActiveControl property.
      Public Property ActiveControl() As Control Implements IContainerControl.ActiveControl
         Get
            Return Me.myActiveControl
         End Get
         
         Set
            ' Make sure the control is a member of the ControlCollection.
            If Me.Controls.Contains(value) Then
               Me.myActiveControl = value
            End If
         End Set
      End Property
      
      ' Add implementation to the IContainerControl.ActivateControl(Control) method.
      public Function ActivateControl(active As Control) As Boolean Implements IContainerControl.ActivateControl
         If Me.Controls.Contains(active) Then
            ' Select the control and scroll the control into view if needed.
            active.Select()
            Me.ScrollControlIntoView(active)
            Me.myActiveControl = active
            Return True
         End If
         Return False
      End Function 

   End Class  

설명

ActiveControl 속성 활성화 하거나 컨테이너 컨트롤에 있는 활성 컨트롤을 검색 합니다.The ActiveControl property activates or retrieves the active control on the container control.

이 속성에서 올바른 값을 받으려면 호출 하는 개체 포함 하거나 또는 호출 하는 컨트롤에 포함 되어야 합니다.In order to receive a valid value from this property, the object that calls it must either contain or be contained in the control it is calling. 폼에서 또 다른 형태를 호출 하려고 하는 경우 ActiveControl 속성을 정의 되지 않은 값을 받게 됩니다.If one form tries to call another form's ActiveControl properties, it will receive an undefined value. 이 경우이 데이터를 전달 하 여 폼 간에 직접 통신 메커니즘을 정의 해야 합니다.In this case, you need to define your own communication mechanism between the forms to pass this data.

적용 대상

추가 정보