Freigeben über


ContainerControl.ActiveControl-Eigenschaft

Ruft das aktive Steuerelement im Containersteuerelement ab oder legt dieses fest.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
Public Property ActiveControl As Control
'Usage
Dim instance As ContainerControl
Dim value As Control

value = instance.ActiveControl

instance.ActiveControl = value
public Control ActiveControl { get; set; }
public:
virtual property Control^ ActiveControl {
    Control^ get () sealed;
    void set (Control^ value) sealed;
}
/** @property */
public final Control get_ActiveControl ()

/** @property */
public final void set_ActiveControl (Control value)
public final function get ActiveControl () : Control

public final function set ActiveControl (value : Control)

Eigenschaftenwert

Das derzeit aktive Control in ContainerControl.

Ausnahmen

Ausnahmetyp Bedingung

ArgumentException

Das zugewiesene Control konnte nicht aktiviert werden.

Hinweise

Die ActiveControl-Eigenschaft aktiviert das aktive Steuerelement des Containersteuerelements oder ruft das aktive Steuerelement ab.

Um einen gültigen Wert von dieser Eigenschaft zu erhalten, muss das aufrufende Objekt das aufgerufene Steuerelement entweder enthalten, oder es muss in diesem enthalten sein. Wenn ein Formular versucht, die ActiveControl-Eigenschaften eines anderen Formulars aufzurufen, erhält es einen nicht definierten Wert. In diesem Fall müssen Sie einen eigenen Kommunikationsmechanismus zwischen den Formularen definieren, um die Daten zu übergeben.

Beispiel

Im folgenden Codebeispiel wird die ScrollableControl-Klasse geerbt. Außerdem wird die IContainerControl-Schnittstelle implementiert. Der ActiveControl-Eigenschaft und der ActivateControl-Methode wird eine Implementierung hinzugefügt.

Imports System
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  
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;
        }
    }
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;
   }
};
import System.*;
import System.Windows.Forms.*;
import System.Drawing.*;

public class MyContainer extends ScrollableControl implements IContainerControl
{
    private Control activeControl;

    public MyContainer()
    {
        // Make the container control Blue so it can be 
        // distinguished on the form.
        this.set_BackColor(Color.get_Blue());

        // Make the container scrollable.
        this.set_AutoScroll(true);
    } //MyContainer

    // Add implementation to the IContainerControl.ActiveControl property.
    /** @property 
     */
    public Control get_ActiveControl()
    {
        return activeControl;
    } //get_ActiveControl

    /** @property 
     */
    public void set_ActiveControl(Control value)
    {
        // Make sure the control is a member of the ControlCollection.
        if (this.get_Controls().Contains(value)) {
            activeControl = value;
        }
    } //set_ActiveControl

    // Add implementations to the IContainerControl.
    // ActivateControl(Control) method.
    public boolean ActivateControl(Control active)
    {
        if (this.get_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;
    } //ActivateControl
} //MyContainer

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

ContainerControl-Klasse
ContainerControl-Member
System.Windows.Forms-Namespace
ScrollableControl
Control