ContainerControl Class
Assembly: System.Windows.Forms (in system.windows.forms.dll)
'Declaration <ComVisibleAttribute(True)> _ <ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _ Public Class ContainerControl Inherits ScrollableControl Implements IContainerControl 'Usage Dim instance As ContainerControl
/** @attribute ComVisibleAttribute(true) */ /** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ public class ContainerControl extends ScrollableControl implements IContainerControl
ComVisibleAttribute(true) ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) public class ContainerControl extends ScrollableControl implements IContainerControl
A ContainerControl represents a control that can function as a container for other controls and provides focus management. Controls that inherit from this class can track the active control they contain, even when the focus moves somewhere within a different container.
ContainerControl objects provide a logical boundary for contained controls. The container control can capture the TAB key press and move focus to the next control in the collection.
Note |
|---|
| The container control does not receive focus; the focus is always set to the first child control in the collection of contained controls. |
You do not typically inherit directly from the ContainerControl class. Form, UserControl, and UpDownBase classes inherit from ContainerControl.
The following code example inherits from the ScrollableControl class and implements the IContainerControl interface. Implementation is added to the ActiveControl property and the ActivateControl method.
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
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
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.ScrollableControl
System.Windows.Forms.ContainerControl
Derived Classes
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Note